home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 25 / Mac Magazin and MacEasy Magazine CD - Issue 25.iso / Grafik & Text / Alpha / Tcl / Modes / latexMacros.tcl (.txt) < prev    next >
LaTeX Document  |  1996-08-15  |  94KB  |  2,681 lines

  1. #############################################################################
  2. #############################################################################
  3. # latexMacros.tcl (called from latex.tcl)
  4. #############################################################################
  5. # Author:  Tom Scavo <trscavo@syr.edu>
  6. #############################################################################
  7. #############################################################################
  8. #############################################################################
  9. # Basic Commands
  10. #############################################################################
  11. #--------------------------------------------------------------------------
  12. # Goto:
  13. #--------------------------------------------------------------------------
  14. # Switch to (but don't execute) any of the following applications.
  15. proc latex {} {
  16.     global texSig texAppSig
  17.     set supportedApps [array names texAppSig]
  18.     foreach app $supportedApps { lappend sigs $texAppSig($app) }
  19.     set longPrompt "Please locate your TeX app."
  20.     if { [catch {launchBackApplSigs $sigs texSig $longPrompt} appname] } {
  21.         error "bug in 'launchBackApplSigs'"
  22.     set quotedSig "'[string trim $texSig {'}]'"
  23.     switchTo $quotedSig
  24. proc bibtex {} {
  25.     global bibtexSig bibtexAppSig
  26.     set supportedApps [array names bibtexAppSig]
  27.     foreach app $supportedApps { lappend sigs $bibtexAppSig($app) }
  28.     set longPrompt "Please locate your BibTeX app."
  29.     if { [catch {launchBackApplSigs $sigs bibtexSig $longPrompt} appname] } {
  30.         error "bug in 'launchBackApplSigs'"
  31.     set quotedSig "'[string trim $bibtexSig {'}]'"
  32.     switchTo $quotedSig
  33. proc makeindex {} {
  34.     global makeindexSig makeindexAppSig
  35.     set supportedApps [array names makeindexAppSig]
  36.     foreach app $supportedApps { lappend sigs $makeindexAppSig($app) }
  37.     set longPrompt "Please locate your MakeIndex app."
  38.     if { [catch {launchBackApplSigs $sigs makeindexSig $longPrompt} appname] } {
  39.         error "bug in 'launchBackApplSigs'"
  40.     set quotedSig "'[string trim $makeindexSig {'}]'"
  41.     switchTo $quotedSig
  42. # Find the next or previous environment.  Search forward (or backward, 
  43. # depending on $forward) for either \begin or \end.  If \begin is found, 
  44. # search forward for corresponding \end; otherwise, search backward for 
  45. # corresponding \begin.  Select the found environment, or display an 
  46. # error message if no environment is found.
  47. proc findEnvironment {forward} {
  48.     set searchString1 {^[ \t]*\\begin\{[^\{\}]*\}|\\end\{[^\{\}]*\}[ \t]*\r?}
  49.     set searchPos [getPos]
  50.     if { [isSelection] } then { 
  51.         if { $forward } then {
  52.             set searchPos [selEnd]
  53.         } else {
  54.             set searchPos [expr $searchPos - 1]
  55.     } else {
  56.         if { $forward } then {
  57.             set searchPos [expr $searchPos + 1]
  58.         } else {
  59.             set searchPos [expr $searchPos - 1]
  60.     set searchResult [search -s -f $forward -r 1 -n $searchString1 $searchPos]
  61.     if {[string length $searchResult]} then {
  62.         set begPos [lindex $searchResult 0]
  63.         set endPos [lindex $searchResult 1]
  64.         set searchText [getText $begPos $endPos]
  65.         regexp {\{(.*)\}} $searchText dummy envName
  66.         if {[string match {*begin*} $searchText]} {
  67.             set begEnv $begPos
  68.             append searchString2 {\\end\{} $envName {\}[ \t]*\r?}
  69.             set searchPos $endPos
  70.             set searchResult [search -s -f 1 -r 1 -n $searchString2 $searchPos]
  71.             if {[string length $searchResult]} {
  72.                 set endPos [lindex $searchResult 1]
  73.                 return [list $begPos $endPos]
  74.             } else {
  75.                 return "matching \\end not found"
  76.         } else {
  77.             set endEnv $endPos
  78.             append searchString2 {^[ \t]*\\begin\{} $envName {\}}
  79.             set searchPos $begPos
  80.             set searchResult [search -s -f 0 -r 1 -n $searchString2 $searchPos]
  81.             if {[string length $searchResult]} {
  82.                 set begPos [lindex $searchResult 0]
  83.                 return [list $begPos $endPos]
  84.             } else {
  85.                 return "matching \\begin not found"
  86.     } else {
  87.         if { $forward } then {
  88.             return "next environment not found"
  89.         } else {
  90.             return "previous environment not found"
  91. proc prevEnvironment {} {
  92.     global searchNoisily
  93.     set findResult [findEnvironment 0]
  94.     if {[llength $findResult] == 2} then {
  95.         goto [lindex $findResult 0]
  96.     } else {
  97.         if {$searchNoisily} {beep}
  98.         message $findResult
  99. proc nextEnvironment {} {
  100.     global searchNoisily
  101.     set findResult [findEnvironment 1]
  102.     if {[llength $findResult] == 2} then {
  103.         goto [lindex $findResult 0]
  104.     } else {
  105.         if {$searchNoisily} {beep}
  106.         message $findResult
  107. proc prevEnvironmentSelect {} {
  108.     global searchNoisily
  109.     set forward 0
  110.     set findResult [findEnvironment $forward]
  111.     if {[llength $findResult] == 2} then {
  112.         set endPos [lindex $findResult 1]
  113. #         if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
  114. #             set endPos [expr $endPos + 1]
  115. #         }
  116.         select [lindex $findResult 0] $endPos
  117.     } else {
  118.         if { $searchNoisily } {beep}
  119.         message $findResult
  120. proc nextEnvironmentSelect {} {
  121.     global searchNoisily
  122.     set forward 1
  123.     set findResult [findEnvironment $forward]
  124.     if {[llength $findResult] == 2} then {
  125.         set endPos [lindex $findResult 1]
  126. #         if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
  127. #             set endPos [expr $endPos + 1]
  128. #         }
  129.         select [lindex $findResult 0] $endPos
  130.     } else {
  131.         if { $searchNoisily } {beep}
  132.         message $findResult
  133. # Find a LaTeX command in either direction.  It's up to the calling
  134. # procedure to pass the correct starting position of the search.
  135. proc findCommand {pos direction} {
  136. #    Handle "\ " and "\[" separately:
  137.     set searchString {(\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?)|([^\\]\\\ )|([^\\]\\\[)}
  138.     set searchResult [search -s -f $direction -r 1 -n $searchString $pos]
  139.     if { [string length $searchResult] } {
  140.         set begPos [lindex $searchResult 0]
  141.         set endPos [lindex $searchResult 1]
  142.         set lastChar [lookAt [expr $endPos - 1]]
  143.         if {$lastChar == "\ " || $lastChar == "\["} then {
  144.             return [list [expr $begPos + 1] $endPos]
  145.         } else {}
  146.     return $searchResult
  147. # Handles everything but "\ " and "\[":
  148. #     set searchString {\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?}
  149. #     return [search -s -f $direction -r 1 -n $searchString $pos]
  150. # Find and goto the beginning of the previous LaTeX command.
  151. proc prevCommand {} {
  152.     global searchNoisily
  153.     set pos [getPos]
  154.     if {$pos > 0} then {
  155.         set searchResult [findCommand [expr $pos - 1] 0]
  156.         if { [string length $searchResult] } {
  157.             goto [lindex $searchResult 0]
  158.             return
  159.         } else {}
  160.     if { $searchNoisily } {beep}
  161.     message "previous command not found"
  162. # Find and goto the beginning of the next LaTeX command.
  163. proc nextCommand {} {
  164.     global searchNoisily
  165.     set pos [getPos]
  166.     if {$pos < [maxPos]} then {
  167.         set searchResult [findCommand [expr $pos + 1] 1]
  168.         if { [string length $searchResult] } {
  169.             goto [lindex $searchResult 0]
  170.             return
  171.         } else {}
  172.     if { $searchNoisily } {beep}
  173.     message "next command not found"
  174. # Select the previous LaTeX command, but do not attempt to select
  175. # any associated argument.
  176. proc prevCommandSelect {} {
  177.     global searchNoisily
  178.     set pos [getPos]
  179.     if {$pos > 0} then {
  180.         set searchResult [findCommand [expr $pos - 1] 0]
  181.         if { [string length $searchResult] } {
  182.             eval select $searchResult
  183.             return
  184.         } else {}
  185.     if { $searchNoisily } {beep}
  186.     message "previous command not found"
  187. # Select the next LaTeX command, but do not attempt to select
  188. # any associated argument.
  189. proc nextCommandSelect {} {
  190.     global searchNoisily
  191.     set pos [getPos]
  192.     if {$pos < [maxPos]} then {
  193.         if { [isSelection] } then {
  194.             set pos [expr $pos + 1]
  195.         set searchResult [findCommand $pos 1]
  196.         if { [string length $searchResult] } {
  197.             eval select $searchResult
  198.             return
  199.         } else {}
  200.     if { $searchNoisily } {beep}
  201.     message "next command not found"
  202. # Find a LaTeX command with arguments in either direction.  It's up 
  203. # to the calling procedure to pass the starting position of the search.
  204. # (Handles everything but "\ " and commands whose arguments contain
  205. # embedded braces.)
  206. proc findCommandWithArgs {pos direction} {
  207.     set searchString {\\([^a-zA-Z\t\r]|[a-zA-Z]+\*?)(\[.*\])*({[^{}]*})*}
  208.     return [search -s -f $direction -r 1 -n $searchString $pos]
  209. # Select the previous LaTeX command and any associated arguments.
  210. proc prevCommandSelectWithArgs {} {
  211.     global searchNoisily
  212.     set pos [getPos]
  213.     if {$pos > 0} then {
  214.         set searchResult [findCommandWithArgs [expr $pos - 1] 0]
  215.         if { [string length $searchResult] } {
  216.             eval select $searchResult
  217.             return
  218.         } else {}
  219.     if { $searchNoisily } {beep}
  220.     message "previous command not found"
  221. # Select the next LaTeX command and any associated arguments.
  222. proc nextCommandSelectWithArgs {} {
  223.     global searchNoisily
  224.     set pos [getPos]
  225.     if {$pos < [maxPos]} then {
  226.         if { [isSelection] } then {
  227.             set pos [expr $pos + 1]
  228.         set searchResult [findCommandWithArgs $pos 1]
  229.         if { [string length $searchResult] } {
  230.             eval select $searchResult
  231.             return
  232.         } else {}
  233.     if { $searchNoisily } {beep}
  234.     message "next command not found"
  235. # Find a LaTeX sectioning command in either direction.  It's up to 
  236. # the calling procedure to pass the starting position of the search.
  237. proc findSection {pos direction} {
  238.     global funcExprAlt
  239.     return [search -s -f $direction -r 1 -n $funcExprAlt $pos]
  240. # Select the previous LaTeX sectioning command.
  241. proc prevSection {} {
  242.     global searchNoisily
  243.     set pos [getPos]
  244.     if {$pos > 0} then {
  245.         set searchResult [findSection [expr $pos - 1] 0]
  246.         if { [string length $searchResult] } {
  247.             eval select $searchResult
  248.             return
  249.         } else {}
  250.     if { $searchNoisily } {beep}
  251.     message {previous section not found}
  252. # Select the next LaTeX sectioning command.
  253. proc nextSection {} {
  254.     global searchNoisily
  255.     set pos [getPos]
  256.     if {$pos < [maxPos]} then {
  257.         if { [isSelection] } then {
  258.             set pos [expr $pos + 1]
  259.         set searchResult [findSection $pos 1]
  260.         if { [string length $searchResult] } {
  261.             eval select $searchResult
  262.             return
  263.         } else {}
  264.     if { $searchNoisily } {beep}
  265.     message {next section not found}
  266. proc prevSectionSelect {} {
  267.     global searchNoisily
  268.     set pos [getPos]
  269.     if {$pos > 0} then {
  270.         set searchResult [findSection [expr $pos - 1] 0]
  271.         if { [string length $searchResult] } {
  272.             set begPos [lindex $searchResult 0]
  273.             set searchPos [expr [lindex $searchResult 1] + 1]
  274.             set searchResult [findSection $searchPos 1]
  275.             if { [string length $searchResult] } {
  276.                 set endPos [lindex $searchResult 0]
  277.             } else {
  278.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  279.                 set endPos [lindex $searchResult 0]
  280.             select $begPos $endPos
  281.             return
  282.         } else {}
  283.     if { $searchNoisily } {beep}
  284.     message {previous section not found}
  285. # Select the next LaTeX sectioning command.
  286. proc nextSectionSelect {} {
  287.     global searchNoisily
  288.     set pos [getPos]
  289.     if {$pos < [maxPos]} then {
  290.         if { [isSelection] } then {
  291.             set pos [expr $pos + 1]
  292.         set searchResult [findSection $pos 1]
  293.         if { [string length $searchResult] } {
  294.             set begPos [lindex $searchResult 0]
  295.             set searchPos [expr [lindex $searchResult 1] + 1]
  296.             set searchResult [findSection $searchPos 1]
  297.             if { [string length $searchResult] } {
  298.                 set endPos [lindex $searchResult 0]
  299.             } else {
  300.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  301.                 set endPos [lindex $searchResult 0]
  302.             select $begPos $endPos
  303.             return
  304.         } else {}
  305.     if { $searchNoisily } {beep}
  306.     message {next section not found}
  307. # Find a LaTeX subsectioning command in either direction.  It's up to 
  308. # the calling procedure to pass the starting position of the search.
  309. proc findSubsection {pos direction} {
  310.     global funcExpr
  311.     return [search -s -f $direction -r 1 -n $funcExpr $pos]
  312. proc prevSubsection {} {
  313.     global searchNoisily
  314.     set pos [getPos]
  315.     if {$pos > 0} then {
  316.         set searchResult [findSubsection [expr $pos - 1] 0]
  317.         if { [string length $searchResult] } {
  318.             eval select $searchResult
  319.             return
  320.         } else {}
  321.     if { $searchNoisily } {beep}
  322.     message {previous (sub)*section not found}
  323. # Select the next LaTeX sectioning command.
  324. proc nextSubsection {} {
  325.     global searchNoisily
  326.     set pos [getPos]
  327.     if {$pos < [maxPos]} then {
  328.         if { [isSelection] } then {
  329.             set pos [expr $pos + 1]
  330.         set searchResult [findSubsection $pos 1]
  331.         if { [string length $searchResult] } {
  332.             eval select $searchResult
  333.             return
  334.         } else {}
  335.     if { $searchNoisily } {beep}
  336.     message {next (sub)*section not found}
  337. proc prevSubsectionSelect {} {
  338.     global searchNoisily
  339.     set pos [getPos]
  340.     if {$pos > 0} then {
  341.         set searchResult [findSubsection [expr $pos - 1] 0]
  342.         if { [string length $searchResult] } {
  343.             set begPos [lindex $searchResult 0]
  344.             set endPos [lindex $searchResult 1]
  345.             set searchPos [expr $endPos + 1]
  346.             set commandName [extractCommandName [getText $begPos $endPos]]
  347.             if {[string match {section*} $commandName]} then {
  348.                 set searchResult [findSection $searchPos 1]
  349.             } else {
  350.                 set searchResult [findSubsection $searchPos 1]
  351.             if { [string length $searchResult] } {
  352.                 set endPos [lindex $searchResult 0]
  353.             } else {
  354.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  355.                 set endPos [lindex $searchResult 0]
  356.             select $begPos $endPos
  357.             return
  358.         } else {}
  359.     if { $searchNoisily } {beep}
  360.     message {previous (sub)*section not found}
  361. # Select the next LaTeX sectioning command.
  362. proc nextSubsectionSelect {} {
  363.     global searchNoisily
  364.     set pos [getPos]
  365.     if {$pos < [maxPos]} then {
  366.         if { [isSelection] } then {
  367.             set pos [expr $pos + 1]
  368.         set searchResult [findSubsection $pos 1]
  369.         if { [string length $searchResult] } {
  370.             set begPos [lindex $searchResult 0]
  371.             set endPos [lindex $searchResult 1]
  372.             set searchPos [expr $endPos + 1]
  373.             set commandName [extractCommandName [getText $begPos $endPos]]
  374.             if {[string match {section*} $commandName]} then {
  375.                 set searchResult [findSection $searchPos 1]
  376.             } else {
  377.                 set searchResult [findSubsection $searchPos 1]
  378.             if { [string length $searchResult] } {
  379.                 set endPos [lindex $searchResult 0]
  380.             } else {
  381.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  382.                 set endPos [lindex $searchResult 0]
  383.             select $begPos $endPos
  384.             return
  385.         } else {}
  386.     if { $searchNoisily } {beep}
  387.     message {next (sub)*section not found}
  388. proc gotoTabStop {dirIndicator} {
  389.     set pos [getPos]
  390.     if {$dirIndicator} then {
  391.         if {$pos == [maxPos]} { return 0 }
  392.     } else {
  393.         if {$pos == 0} { return 0 }
  394.         # Fixes a bug in 'search':
  395.         set pos [expr $pos - 1]
  396.     set searchResult [search -s -n -f $dirIndicator -m 0 -i 1 -r 0 {
  397. } $pos]
  398.     if {[string length $searchResult]} then {
  399.         goto [lindex $searchResult 0]
  400.         return 1
  401.     } else {
  402.         return 0
  403. proc nextTabStop {} {
  404.     global searchNoisily
  405.     set forward 1
  406.     if { [gotoTabStop $forward] } then {
  407.         deleteChar
  408.     } else {
  409.         if { $searchNoisily } {beep}
  410.         message "tab stop not found"
  411. proc prevTabStop {} {
  412.     global searchNoisily
  413.     set forward 0
  414.     if { [gotoTabStop $forward] } then {
  415.         deleteChar
  416.     } else {
  417.         if { $searchNoisily } {beep}
  418.         message "tab stop not found"
  419. # Goto the nth tab stop.  A nonzero argument is non-interactive
  420. # (for use in Tcl procs) and not validated.
  421. proc nthTabStop {{numTabStops 0}} {
  422.     global searchNoisily promptNoisily useStatusBar
  423.     if { $numTabStops == 0 } then {
  424.         if { $promptNoisily && $useStatusBar } { beep }
  425.         catch {sPrompt "How many tab stops?" "3"} numTabStops
  426.         if { $numTabStops == "cancel" || $numTabStops == 0 } then {
  427.             return
  428.         } elseif { ![isInteger $numTabStops] } then {
  429.             beep
  430.             message "invalid input:  integer required"
  431.             return
  432.     set currentPos [getPos]
  433.     if { $numTabStops > 0 } { set forward 1 } { set forward 0 }
  434.     set maxits [expr abs($numTabStops)]
  435.     if { ![gotoTabStop $forward] } then {
  436.         if { $searchNoisily } {beep}
  437.         message "tab stop not found"
  438.         goto $currentPos
  439.         return
  440.     for { set i 1 } { $i < $maxits } { incr i } {
  441.         if { $forward } { forwardChar } { backwardChar }
  442.         if { ![gotoTabStop $forward] } then {
  443.             if { $searchNoisily } { beep }
  444.             message "tab stop not found"
  445.             goto $currentPos
  446.             return
  447.     deleteChar
  448. #--------------------------------------------------------------------------
  449. # Utilities:
  450. #--------------------------------------------------------------------------
  451. # A keyboard-bound method of accessing menu commands.  Takes a list of 
  452. # menu items (i.e., the tail of a 'menu' command), the menu name (the 
  453. # argument of the '-n' switch) , and the name of a menu filter (the 
  454. # argument of the '-p' switch) as input, and displays these items in a 
  455. # list box.  If the chosen item is a menu command (as opposed to a 
  456. # submenu), it is passed to the menu filter; otherwise, 'chooseCommand' 
  457. # recursively calls itself until a menu command is chosen or the cancel 
  458. # button is pressed.
  459. proc chooseCommand {menuItems {menuName ""} {menuFilterProc ""} {level 1}} {
  460.     watchCursor
  461.     if { $menuItems == "" } { return }
  462.     # Preprocess the list of menu items:
  463.     foreach    item $menuItems {
  464.         regsub -all {[<!/].} $item {} item
  465.         regsub -all {
  466. }    $item {} item
  467.         lappend    menOut $item
  468.         if { [string match "menu*" $item] } {
  469.             if { [set ind [lsearch $item {-n}]] >= 0 } {
  470.                 lappend    top "[lindex $item [incr    ind]]:"
  471.         } elseif { ![string match "(*" $item] } {
  472.             lappend    top $item
  473.     # Present the menu items to the user:
  474.     set res    [listpick -p "Choose menu command (level $level):" $top]
  475.     # Either execute a command or recurse on a submenu:
  476.     if { [lsearch $menOut $res] >= 0 } {
  477.         # Execute the command via the menu filter, if necessary:
  478.         if { $menuFilterProc == "" } {
  479.             $res
  480.         } else {
  481.             $menuFilterProc $menuName $res
  482.     } else {
  483.         set res [string trimright $res {:}]
  484.         foreach    item $menOut {
  485.             if { [lsearch $item $res] >= 0 } {
  486.                 set menuItems [lindex $item end]
  487.                 # Determine the name of this submenu:
  488.                 if { [set ind [lsearch $item {-n}]] >= 0 } {
  489.                     set menuName [lindex $item [incr ind]]
  490.                 } else {
  491.                     set menuName ""
  492.                 }
  493.                 # Determine the name of the menu filter for this submenu:
  494.                 if { [set ind [lsearch $item {-p}]] >= 0 } {
  495.                     set menuFilterProc [lindex $item [incr ind]]
  496.                 } else {
  497.                     set menuFilterProc ""
  498.                 }
  499.                 return [chooseCommand $menuItems $menuName $menuFilterProc [incr level]]
  500. proc insertLiteralTab {} {
  501.     if {[isSelection]} then {
  502.         deleteSelection
  503.     insertText "\t"
  504. proc insertTabStop {} {
  505.     if {[isSelection]} then {
  506.         deleteSelection
  507.     insertText "
  508. # Removes all tab stops from the current selection (if there is one) 
  509. # or the current document, maintaining the cursor position in the 
  510. # latter case.
  511. proc deleteTabStops {} {
  512.     global searchNoisily
  513.     watchCursor
  514.     set subs1 0; set subs2 0; set subs3 0
  515.     set pos [getPos]
  516.     if {[set start $pos] == [set end [selEnd]]} {
  517.         set messageString "document"
  518.         set start 0
  519.         set end [maxPos]
  520.         set text1 [getText $start $pos]
  521.         set subs1 [regsub -all {
  522. } $text1 {} text1]
  523.         set text2 [getText $pos $end]
  524.         set subs2 [regsub -all {
  525. } $text2 {} text2]
  526.         append text $text1 $text2
  527.     } else {
  528.         set messageString "selection"
  529.         set text [getText $start $end]
  530.         set subs3 [regsub -all {
  531. } $text {} text]
  532.     if {$subs1 || $subs2 || $subs3} then {
  533.         replaceText $start $end $text
  534.         if {$messageString == "document"} then {
  535.             goto [expr $pos - $subs1]
  536.         } else {
  537.             set end [getPos]
  538.             select $start $end
  539.         set subs [expr $subs1 + $subs2 + $subs3]
  540.         message "$subs tab stops removed from $messageString"
  541.     } else {
  542.         if {$searchNoisily} {beep}
  543.         message "no tab stops found in $messageString"
  544. # Delete all unnecessary comments from the current document:
  545. proc deleteComments {} {
  546.     switch [askyesno "Warning!  This operation can not be undone.  \
  547.                     Continue anyway?"] {
  548.         "yes" {}
  549.         "no" { return }
  550.     replaceString {}
  551.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {^[ \t]*%.*\r} 0]
  552.     replaceAll
  553.     replaceString {}
  554.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {[ \t]+%.*} 0]
  555.     replaceAll
  556.     replaceString {\1%}
  557.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {([^\\](\\\\)*)%.*} 0]
  558.     replaceAll
  559. # Converts all straight quotes to their TeX equivalents.
  560. proc convertQuotes {} {
  561.     global searchNoisily
  562.     message "working
  563.     watchCursor
  564.     set messageString "selection"
  565.     if {[set start [getPos]] == [set end [selEnd]]} {
  566.         set messageString "document"
  567.         set start 0
  568.         set end [maxPos]
  569.     set text [getText $start $end]
  570.     # Convert all left double quotes:
  571.     set convert1 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\"" $text {\1``} text]
  572.     # Convert all right double quotes:
  573.     set convert2 [regsub -all "\(\[\^\\\\\]\)\"" $text {\1''} text]
  574.     # Convert all left single quotes:
  575.     set convert3 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\'" $text {\1`} text]
  576.     if {$convert1 || $convert2 || $convert3} then {
  577.         replaceText $start $end $text
  578.         message "all quotes in $messageString converted"
  579.     } else {
  580.         if {$searchNoisily} {beep}
  581.         message "no quotes found in $messageString"
  582. # Returns true if the argument contains non-literal double dollar
  583. # signs, and false otherwise.
  584. proc containsDoubleDollarSigns {text} {
  585.     return [regexp {(^|[^\\])\$\$} $text]
  586. # Converts all $$...$$ pairs to \[...\] and returns the number of such 
  587. # pairs converted.  If the dollar signs are unbalanced, does nothing 
  588. # and returns -1.
  589. proc convertDoubleDollarSigns {} {
  590.     watchCursor
  591.     set messageString "selection"
  592.     if {[set start [getPos]] == [set end [selEnd]]} {
  593.         set messageString "document"
  594.         set start 0
  595.         set end [maxPos]
  596.     set text [getText $start $end]
  597.     set subs [regsub -all {(^|[^\\])\$\$([^$]*)\$\$} $text {\1\\[\2\\]} text]
  598.     if {[containsDoubleDollarSigns $text]} then {return -1}
  599.     if {$subs} then {
  600.         replaceText $start $end $text
  601.     return [expr $subs]
  602. # Returns true if the argument contains a non-literal dollar sign,
  603. # and false otherwise.
  604. proc containsSingleDollarSign {text} {
  605.     return [regexp {(^|[^\\])\$} $text]
  606. # Converts all $...$ pairs to \(...\), maintains the cursor position, 
  607. # and returns the number of such pairs converted.  If the dollar signs 
  608. # are unbalanced, does nothing and returns -1.
  609. proc convertSingleDollarSigns {} {
  610.     watchCursor
  611.     set subs1 0; set subs2 0; set subs3 0
  612.     set pos [getPos]; set pos2 $pos
  613.     if {[set start $pos] == [set end [selEnd]]} {
  614.         set isSelection 0
  615.         set start 0
  616.         set end [maxPos]
  617.         set text1 [getText $start $pos]
  618.         set subs1 [regsub -all {(^|[^\\])\$([^$]*)\$} $text1 {\1\\(\2\\)} text1]
  619.         # Is there a dollar sign left over?  If so, search backward for this
  620.         # dollar sign and prepare to do a substitution on the text to the right
  621.         # of this dollar sign.
  622.         if {[containsSingleDollarSign $text1]} then {
  623.             set searchString {[^\\]\$}
  624.             set searchResult [search -s -n -f 0 -m 0 -i 1 -r 1 $searchString [expr $pos-1]]
  625.             set pos2 [lindex $searchResult 0]
  626.             set text1 [string range $text1 0 [expr $pos2 + (2 * $subs1)]]
  627.             set pos [expr $pos + 2]
  628.         set text2 [getText $pos2 $end]
  629.         set subs2 [regsub -all {(^|[^\\])\$([^$]*)\$} $text2 {\1\\(\2\\)} text2]
  630.         # Is there a dollar sign left over?  If so, it's unbalanced.
  631.         if {[containsSingleDollarSign $text2]} then {return -1}
  632.         append text $text1 $text2
  633.     } else {
  634.         set isSelection 1
  635.         set text [getText $start $end]
  636.         set subs3 [regsub -all {(^|[^\\])\$([^$]*)\$} $text {\1\\(\2\\)} text]
  637.         # Is there a dollar sign left over?  If so, it's unbalanced.
  638.         if {[containsSingleDollarSign $text]} then {return -1}
  639.     if {$subs1 || $subs2 || $subs3} then {
  640.         replaceText $start $end $text
  641.         # If there is a selection, just put it back.  Otherwise, adjust the
  642.         # cursor position based on the number of substitutions.
  643.         if {$isSelection} then {
  644.             set end [getPos]
  645.             select $start $end
  646.         } else {
  647.             goto [expr $pos + (2 * $subs1)]
  648.     return [expr $subs1 + $subs2 + $subs3]
  649. proc convertDollarSigns {} {
  650.     global searchNoisily
  651.     if {[isSelection]} then {
  652.         set messageString "selection"
  653.     } else {
  654.         set messageString "document"
  655.     set subs2 [convertDoubleDollarSigns]
  656.     if {$subs2 == -1} then {
  657.         beep
  658.         alertnote "unmatched double dollar signs in $messageString"
  659.     } else {
  660.         set subs1 [convertSingleDollarSigns]
  661.         if {$subs1 == -1} then {
  662.             beep
  663.             alertnote "unmatched single dollar sign in $messageString"
  664.         } elseif {$subs1 == 0 && $subs2 == 0} then {
  665.             if {$searchNoisily} {beep}
  666.             message "no dollar signs found in $messageString"
  667.         } else {
  668.             message "$subs1 pairs of \$
  669. \$ and $subs2 pairs of \$\$
  670. \$\$ removed from $messageString"
  671. #############################################################################
  672. # Paragraph Mode Macros
  673. #############################################################################
  674. #--------------------------------------------------------------------------
  675. # Documents:
  676. #--------------------------------------------------------------------------
  677. proc newLaTeXDocument {} {
  678.     catch {prompt "Choose a documentclass:" "article" "" "article" \
  679.             "report" "book" "letter" "slides"} documentType
  680.     if {$documentType != "cancel"} then {
  681.         new
  682.         newMode TeX
  683.         if { [catch {${documentType}Documentclass}] } then {
  684.             wrapDocument "$documentType" 
  685.         while { [options] } {}
  686.         nextTabStop
  687.         message "enter option (or leave blank)"
  688. proc letterDocumentclass {} {
  689.     set    preamble "\r\\address\{%\r"
  690.     append preamble "    
  691.     \\\\    % insert your name here\r"
  692.     append preamble "    
  693.     \\\\    % insert your address here\r"
  694.     append preamble "    
  695.     \\\\    % insert more address here\r"
  696.     append preamble "    
  697.           % insert city-state-zip here\r"
  698.     append preamble "\}\r\r"
  699.     append preamble "\\date\{
  700. \}  % optional\r"
  701.     append preamble "\\signature\{
  702. \}\r\r"
  703.     set    body     "\r\\begin\{letter\}\{%\r"
  704.     append body     "    
  705.     \\\\    % insert addressee's name here\r"
  706.     append body     "    
  707.     \\\\    % insert addressee's address here\r"
  708.     append body     "    
  709.     \\\\    % insert more address here\r"
  710.     append body     "    
  711.           % insert addressee's city-state-zip here\r"
  712.     append body     "\}\r\r"
  713.     append body     "\\opening\{Dear 
  714. ,\}\r\r"
  715.     if {[isEmptyFile]} then {
  716.         append body "% BODY OF LETTER\r"
  717.         append body "
  718. \r\r"
  719.     } else {
  720.         if {[isDocumentSelected]} then {
  721.             set text [getSelect]
  722. #             deleteText 0 [maxPos]
  723.             append body "$text\r"
  724.         } else {
  725.             alertnote "nonempty file:  delete text or \'Select All\'\
  726.                 from the Edit menu"
  727.             return
  728.     append body "\\closing\{Sincerely,\}\r\r"
  729.     append body "\\encl\{
  730. \}\r"
  731.     append body "\\cc\{
  732. \}\r\r"
  733.     append body "\\end\{letter\}\r\r"
  734.     insertDocument "letter" $preamble $body
  735.     nextTabStop
  736.     message "enter option (or leave blank)"
  737. proc articleDocumentclass {} {
  738.     if { [wrapDocument "article"] } {
  739.         nextTabStop
  740.         message "enter option (or leave blank)"
  741. proc reportDocumentclass {} {
  742.     if { [wrapDocument "report"] } {
  743.         nextTabStop
  744.         message "enter option (or leave blank)"
  745. proc bookDocumentclass {} {
  746.     if { [wrapDocument "book"] } {
  747.         nextTabStop
  748.         message "enter option (or leave blank)"
  749. proc slidesDocumentclass {} {
  750.     if { [wrapDocument "slides"] } {
  751.         nextTabStop
  752.         message "enter option (or leave blank)"
  753. proc otherDocumentclass {} {
  754.     catch {prompt "What documentclass?" "article"} documentType
  755.     if {$documentType != "cancel"} then {
  756.         if { [wrapDocument "$documentType"] } {
  757.             nextTabStop
  758.             message "enter option (or leave blank)"
  759. # If an option is inserted, return true; otherwise, return false.
  760. proc options {} {
  761.     set option [getOption]
  762.     if {$option != ""} then {
  763.         insertOption $option
  764.         return 1
  765.     return 0
  766. proc getOption {} {
  767.     catch {prompt "Choose an option:" "11pt" "" "10pt" "11pt" "12pt" "(-" \
  768.             "letterpaper" "legalpaper" "executivepaper" "a4paper" "a5paper" \
  769.             "b5paper" "(-" "landscape" "(-" "final" "draft" "(-" \
  770.             "oneside" "twoside" "(-" "openright" "openany" "(-" \
  771.             "onecolumn" "twocolumn" "(-" "notitlepage" "titlepage" \
  772.                   "openbib" "(-" "leqno" "(-" "fleqn"} optionName
  773.     if {$optionName != "cancel"} then {
  774.         return $optionName
  775.     } else {
  776.         return ""
  777. proc insertOption {option} {
  778.     global TeXmodeVars
  779.     set searchString {\\documentclass}
  780.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  781.     if {[llength $searchResult] == 0} then {
  782.         if { $TeXmodeVars(searchNoisily) } {beep}
  783.         message "can\'t find \\documentclass"
  784.     } else {
  785.         set nextCharPos [lindex $searchResult 1]
  786.         goto $nextCharPos
  787.         set nextChar [lookAt $nextCharPos]
  788.         if {$nextChar == "\["} then {
  789.             forwardChar
  790.             insertText $option
  791.             if {[lookAt [getPos]] != "\]"} then {
  792.                 insertText ","
  793.         } elseif {$nextChar == "\{"} then {
  794.             insertText "\[$option\]"
  795.         } else {
  796.             alertnote "unrecognizable \\documentclass statement"
  797. proc insertPackage {package} {
  798.     global TeXmodeVars
  799.     # Check to see if $package is already loaded:
  800.     if { $package != "" } then {
  801. #         append searchString {\\usepackage\{.*} $package {.*\}}
  802.         append searchString {^[^%]*\\usepackage\{.*} $package {.*\}}
  803.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  804.         if {[llength $searchResult] != 0} then {
  805.             if { $TeXmodeVars(searchNoisily) } {beep}
  806.             message "$package package already loaded"
  807.             return
  808.     # Newlines are allowed in the arguments of \documentclass:
  809.     set searchString {\\documentclass(\[[^][]*\])?{[^{}]*}}
  810.     # Search for \documentclass command:
  811.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  812.     if {[llength $searchResult] == 0} then {
  813.         if { $TeXmodeVars(searchNoisily) } {beep}
  814.         message "can't find \\documentclass"
  815.     } else {
  816.         pushMark
  817.         goto [lindex $searchResult 1]
  818.         set txt "\r\\usepackage\{$package\}"
  819.         insertText $txt
  820.         backwardChar
  821.         message "Press <Ctl .> to return to previous position"
  822. proc filecontents {} {
  823.     global searchNoisily
  824.     set searchString {\\documentclass}
  825.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  826.     if {[llength $searchResult] == 0} then {
  827.         if {$searchNoisily} {beep}
  828.         message "can\'t find \\documentclass"
  829.         return
  830.     } else {
  831.         set prompt "File to be included:"
  832.         if {[catch {getfile $prompt} path]} then {
  833.             return
  834.         } else {
  835.             replaceText 0 0 [buildFilecontents $path]
  836.             goto 0
  837.             message "file included"
  838. proc filecontentsAll {} {
  839.     global searchNoisily
  840.     watchCursor
  841.     message "locating all input files
  842.     set currentWin [lindex [winNames -f] 0]
  843.     # Is the current window part of TeX fileset?
  844.     set fset [isWindowInFileset $currentWin "tex"]
  845.     if { $fset == "" } {
  846.         set searchString {\\documentclass}
  847.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  848.         if {[llength $searchResult] == 0} then {
  849.             if {$searchNoisily} {beep}
  850.             message "can\'t find \\documentclass"
  851.             return
  852.         } else {
  853.             set text [getText 0 [maxPos]]
  854.     } else {
  855.         # Will not handle a base file that is open and dirty:
  856.         set text [buildFilecontents [texFilesetBaseName $fset]]
  857.     set currentDir [file dirname $currentWin]
  858.     set newText [texResolveAll $text $currentDir]
  859.     if { [string length $text] == [string length $newText] } then {
  860.         beep
  861.         message "no files to include"
  862.     } else {
  863.         replaceText 0 [maxPos] $newText
  864.         goto 0
  865.         message "all files included"
  866. # Takes a LaTeX document string and a path as input, and returns
  867. # a modified document string with all filecontents environments
  868. # prepended.
  869. proc texResolveAll {latexDoc currentDir} {
  870.     global TeXmodeVars
  871.     set pairs [list \
  872.                 {{\\documentclass} {.cls}} {{\\LoadClass} {.cls}} \
  873.                 {{\\include} {.tex}} \
  874.                 {{\\usepackage} {.sty}} {{\\RequirePackage} {.sty}} \
  875.                 {{\\input} {}} \
  876.                 {{\\bibliography} {.bib}} {{\\bibliographystyle} {.bst}} \
  877.               ]
  878.     foreach macro $TeXmodeVars(boxMacroNames) {
  879.         regsub {\*} $macro {\\*} macro
  880.         lappend pairs [list \\\\$macro {}]
  881.     foreach pair $pairs {
  882.         set cmd [car $pair]
  883.         set ext [cadr $pair]
  884.         set searchString $cmd
  885.         append searchString {(\[[^][]*\])?{([^{}]*)}}
  886.         set searchText $latexDoc
  887.         while { [regexp -indices $searchString $searchText mtch dummy theArgs] } {
  888.             set begPos [lindex $theArgs 0]
  889.             set endPos [lindex $theArgs 1]
  890.             set args [string range $searchText $begPos $endPos]
  891.             foreach arg [split $args ,] {
  892.                 if { $cmd == {\\input} && ![string length [file extension $arg]] } {
  893.                     set ext {.tex}
  894.                 }
  895.                 set files [glob -nocomplain $currentDir:$arg*]
  896.                 set filename "$currentDir:$arg$ext"
  897.                 if { [lsearch -exact $files $filename] > -1 } {
  898.                     set tempDoc $latexDoc
  899.                     set latexDoc [buildFilecontents $filename]
  900.                     append latexDoc $tempDoc
  901.                 }
  902.             set searchText [string range $searchText [expr $endPos + 2] end]
  903.     return $latexDoc
  904. # Takes a filename as input and returns a filecontents environment 
  905. # based on the contents of that file.  If a second argument is given,
  906. # use that as the argument of the filecontents environment instead
  907. # of the original filename.
  908. proc buildFilecontents {filename {newFilename {}}} {
  909.     set text [readFile $filename]
  910.     # Fix end-of-line characters:
  911.     regsub -all "\xa" $text "\xd" text
  912.     set envName "filecontents"
  913.     if { $newFilename == {} } {
  914.         set envArg "{[file tail $filename]}"
  915.     } else {
  916.         set envArg "{$newFilename}"
  917.     return [buildEnvironment $envName $envArg "$text\r" "\r\r"]
  918. #--------------------------------------------------------------------------
  919. # Page Layout:
  920. #--------------------------------------------------------------------------
  921. proc maketitle {} {
  922.     global searchNoisily
  923.     set searchString {\\document(class|style)(\[.*\])?\{.*\}}
  924.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  925.     if {[llength $searchResult] == 0} then {
  926.         if {$searchNoisily} {beep}
  927.         message "can\'t find \\documentclass or \\documentstyle"
  928.     } else {
  929.         set searchPos [lindex $searchResult 1]
  930.         set searchString {\\begin\{document\}}
  931.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString $searchPos]
  932.         if {[llength $searchResult] == 0} then {
  933.             if {$searchNoisily} {beep}
  934.             message "can\'t find \\begin\{document\}"
  935.         } else {
  936.             goto [lindex $searchResult 1]
  937.             set currentPos [getPos]
  938.             set txt "\r\r% Definition of title page:"
  939.             append txt "\r\\title\{"
  940.             append txt "\r\t
  941. \r\}"
  942.             append txt "\r\\author\{"
  943.             append txt "\r\t
  944. \t% insert author(s) here"
  945.             append txt "\r\}"
  946.             append txt "\r\\date\{
  947. \}\t% optional"
  948.             append txt "\r\r\\maketitle"
  949.             insertText $txt
  950.             goto $currentPos
  951.             nextTabStop
  952.             message "insert title"
  953. proc abstract {} { doWrapEnvironment "abstract" }
  954. proc titlepage {} { doWrapEnvironment "titlepage" }
  955. proc getPagestyle {} {
  956.     catch {prompt "Choose a pagestyle:" "plain" "" "plain" "empty" \
  957.                   "headings" "myheadings"} pagestyleName
  958.     if {$pagestyleName != "cancel"} then {
  959.         return $pagestyleName
  960.     } else {
  961.         return ""
  962. proc pagestyle {} {
  963.     set pagestyleName [getPagestyle]
  964.     if {$pagestyleName != ""} then {
  965.         openingCarriageReturn
  966.         insertObject "\\pagestyle\{$pagestyleName\}"
  967.         closingCarriageReturn
  968. proc thispagestyle {} {
  969.     set pagestyleName [getPagestyle]
  970.     if {$pagestyleName != ""} then {
  971.         openingCarriageReturn
  972.         insertObject "\\thispagestyle\{$pagestyleName\}"
  973.         closingCarriageReturn
  974. proc getPagenumberingStyle {} {
  975.     catch {prompt "Choose a pagenumbering style:" "arabic" "" "arabic" \
  976.                   "roman" "Roman" "alph" "Alph"} pagenumberingStyle
  977.     if {$pagenumberingStyle != "cancel"} then {
  978.         return $pagenumberingStyle
  979.     } else {
  980.         return ""
  981. proc pagenumbering {} {
  982.     set pagenumberingStyle [getPagenumberingStyle]
  983.     if {$pagenumberingStyle != ""} then {
  984.         openingCarriageReturn
  985.         insertObject "\\pagenumbering\{$pagenumberingStyle\}"
  986.         closingCarriageReturn
  987. proc twocolumn {} {
  988.     openingCarriageReturn
  989.     insertObject "\\twocolumn"
  990.     closingCarriageReturn
  991. proc onecolumn {} {
  992.     openingCarriageReturn
  993.     insertObject "\\onecolumn"
  994.     closingCarriageReturn
  995. #--------------------------------------------------------------------------
  996. # Sectioning:
  997. #--------------------------------------------------------------------------
  998. proc part {} {
  999.     if {[wrapObject "\\part{" "}
  1000. "]} then {
  1001.         message "don't forget the label"
  1002.     } else {
  1003.         message "type the part name and don't forget the label"
  1004. proc chapter {} {
  1005.     if {[wrapObject "\\chapter{" "}
  1006. "]} then {
  1007.         message "don't forget the label"
  1008.     } else {
  1009.         message "type the chapter name and don't forget the label"
  1010. proc section {} {
  1011.     if {[wrapObject "\\section{" "}
  1012. "]} then {
  1013.         message "don't forget the label"
  1014.     } else {
  1015.         message "type the section name and don't forget the label"
  1016. proc subsection {} {
  1017.     if {[wrapObject "\\subsection{" "}
  1018. "]} then {
  1019.         message "don't forget the label"
  1020.     } else {
  1021.         message "type the subsection name and don't forget the label"
  1022. proc subsubsection {} {
  1023.     if {[wrapObject "\\subsubsection{" "}
  1024. "]} then {
  1025.         message "don't forget the label"
  1026.     } else {
  1027.         message "type the subsubsection name and don't forget the label"
  1028. proc paragraph {} {
  1029.     if {[wrapObject "\\paragraph{" "}
  1030. "]} then {
  1031.         message "don't forget the label"
  1032.     } else {
  1033.         message "type the paragraph name and don't forget the label"
  1034. proc subparagraph {} {
  1035.     if {[wrapObject "\\subparagraph{" "}
  1036. "]} then {
  1037.         message "don't forget the label"
  1038.     } else {
  1039.         message "type the subparagraph name and don't forget the label"
  1040. proc appendix {} {insertObject "\\appendix"}
  1041. #--------------------------------------------------------------------------
  1042. # Text Style:
  1043. #--------------------------------------------------------------------------
  1044. proc emph {} {
  1045.     if {[wrapObject "\\emph{" "}
  1046. "]} then {
  1047.         message "selected text has been emphasized"
  1048.     } else {
  1049.         message "enter text to be emphasized"
  1050. proc textup {} {
  1051.     if {[wrapObject "\\textup{" "}
  1052. "]} then {
  1053.         message "selected text has upright shape"
  1054.     } else {
  1055.         message "enter text to have upright shape"
  1056. proc textit {} {
  1057.     if {[wrapObject "\\textit{" "}
  1058. "]} then {
  1059.         message "selected text has italic shape"
  1060.     } else {
  1061.         message "enter text to have italic shape"
  1062. proc textsl {} {
  1063.     if {[wrapObject "\\textsl{" "}
  1064. "]} then {
  1065.         message "selected text has slanted shape"
  1066.     } else {
  1067.         message "enter text to have slanted shape"
  1068. proc textsc {} {
  1069.     if {[wrapObject "\\textsc{" "}
  1070. "]} then {
  1071.         message "selected text has small caps shape"
  1072.     } else {
  1073.         message "enter text to have small caps shape"
  1074. proc textmd {} {
  1075.     if {[wrapObject "\\textmd{" "}
  1076. "]} then {
  1077.         message "selected text has been set in medium series"
  1078.     } else {
  1079.         message "enter text to be set in medium series"
  1080. proc textbf {} {
  1081.     if {[wrapObject "\\textbf{" "}
  1082. "]} then {
  1083.         message "selected text has been set in bold series"
  1084.     } else {
  1085.         message "enter text to be set in bold series"
  1086. proc textrm {} {
  1087.     if {[wrapObject "\\textrm{" "}
  1088. "]} then {
  1089.         message "selected text has been set with roman family"
  1090.     } else {
  1091.         message "enter text to be set using roman family"
  1092. proc textsf {} {
  1093.     if {[wrapObject "\\textsf{" "}
  1094. "]} then {
  1095.         message "selected text has been set with sans serif family"
  1096.     } else {
  1097.         message "enter text to be set using sans serif family"
  1098. proc texttt {} {
  1099.     if {[wrapObject "\\texttt{" "}
  1100. "]} then {
  1101.         message "selected text has been set with typewriter family"
  1102.     } else {
  1103.         message "enter text to be set using typewriter family"
  1104. proc textnormal {} {
  1105.     if {[wrapObject "\\textnormal{" "}
  1106. "]} then {
  1107.         message "selected text has been set with normal style"
  1108.     } else {
  1109.         message "enter text to be set using normal style"
  1110. proc em {} {
  1111.     if {[wrapObject "{\\em " "}
  1112. "]} then {
  1113.         message "emphasized text set"
  1114.     } else {
  1115.         message "enter text to be emphasized"
  1116. proc upshape {} {
  1117.     if {[wrapObject "{\\upshape " "}
  1118. "]} then {
  1119.         message "text set in upright shape"
  1120.     } else {
  1121.         message "enter text to be set in upright shape"
  1122. proc itshape {} {
  1123.     if {[wrapObject "{\\itshape " "}
  1124. "]} then {
  1125.         message "text set in italics shape"
  1126.     } else {
  1127.         message "enter text to be set in italics shape"
  1128. proc slshape {} {
  1129.     if {[wrapObject "{\\slshape " "}
  1130. "]} then {
  1131.         message "text set in slanted shape"
  1132.     } else {
  1133.         message "enter text to be set in slanted shape"
  1134. proc scshape {} {
  1135.     if {[wrapObject "{\\scshape " "}
  1136. "]} then {
  1137.         message "text set in small caps shape"
  1138.     } else {
  1139.         message "enter text to be set in small caps shape"
  1140. proc mdseries {} {
  1141.     if {[wrapObject "{\\mdseries " "}
  1142. "]} then {
  1143.         message "text set in medium series"
  1144.     } else {
  1145.         message "enter text to be set in medium series"
  1146. proc bfseries {} {
  1147.     if {[wrapObject "{\\bfseries " "}
  1148. "]} then {
  1149.         message "text set in bold series"
  1150.     } else {
  1151.         message "enter text to be set in bold series"
  1152. proc rmfamily {} {
  1153.     if {[wrapObject "{\\rmfamily " "}
  1154. "]} then {
  1155.         message "text set in roman family"
  1156.     } else {
  1157.         message "enter text to be set in roman family"
  1158. proc sffamily {} {
  1159.     if {[wrapObject "{\\sffamily " "}
  1160. "]} then {
  1161.         message "text set in sans serif family"
  1162.     } else {
  1163.         message "enter text to be set in sans serif family"
  1164. proc ttfamily {} {
  1165.     if {[wrapObject "{\\ttfamily " "}
  1166. "]} then {
  1167.         message "text set in typewriter family"
  1168.     } else {
  1169.         message "enter text to be set in typewriter family"
  1170. proc normalfont {} {
  1171.     if {[wrapObject "{\\normalfont " "}
  1172. "]} then {
  1173.         message "text set in normal style"
  1174.     } else {
  1175.         message "enter text to be set in normal style"
  1176. #--------------------------------------------------------------------------
  1177. # Text Size:
  1178. #--------------------------------------------------------------------------
  1179. proc tiny {} {
  1180.     if {[wrapObject "{\\tiny " "}
  1181. "]} then {
  1182.         message "tiny text set"
  1183.     } else {
  1184.         message "enter tiny text"
  1185. proc scriptsize {} {
  1186.     if {[wrapObject "{\\scriptsize " "}
  1187. "]} then {
  1188.         message "scriptsize text set"
  1189.     } else {
  1190.         message "enter scriptsize text"
  1191. proc footnotesize {} {
  1192.     if {[wrapObject "{\\footnotesize " "}
  1193. "]} then {
  1194.         message "footnotesize text set"
  1195.     } else {
  1196.         message "enter footnotesize text"
  1197. proc small {} {
  1198.     if {[wrapObject "{\\small " "}
  1199. "]} then {
  1200.         message "small text set"
  1201.     } else {
  1202.         message "enter small text"
  1203. proc normalsize {} {
  1204.     if {[wrapObject "{\\normalsize " "}
  1205. "]} then {
  1206.         message "normalsize text set"
  1207.     } else {
  1208.         message "enter normalsize text"
  1209. proc large {} {
  1210.     if {[wrapObject "{\\large " "}
  1211. "]} then {
  1212.         message "large text set"
  1213.     } else {
  1214.         message "enter large text"
  1215. proc Large {} {
  1216.     if {[wrapObject "{\\Large " "}
  1217. "]} then {
  1218.         message "Large text set"
  1219.     } else {
  1220.         message "enter Large text"
  1221. proc LARGE {} {
  1222.     if {[wrapObject "{\\LARGE " "}
  1223. "]} then {
  1224.         message "LARGE text set"
  1225.     } else {
  1226.         message "enter LARGE text"
  1227. proc huge {} {
  1228.     if {[wrapObject "{\\huge " "}
  1229. "]} then {
  1230.         message "huge text set"
  1231.     } else {
  1232.         message "enter huge text"
  1233. proc Huge {} {
  1234.     if {[wrapObject "{\\Huge " "}
  1235. "]} then {
  1236.         message "Huge text set"
  1237.     } else {
  1238.         message "enter Huge text"
  1239. #--------------------------------------------------------------------------
  1240. # International:
  1241. #--------------------------------------------------------------------------
  1242. proc {
  1243. } {} {
  1244.     if {[wrapObject "\\`{" "}
  1245. "]} then {
  1246.         message "accent set"
  1247.     } else {
  1248.         message "enter single character"
  1249. proc {
  1250. } {} {
  1251.     if {[wrapObject "\\'{" "}
  1252. "]} then {
  1253.         message "accent set"
  1254.     } else {
  1255.         message "enter single character"
  1256. proc {
  1257. } {} {
  1258.     if {[wrapObject "\\^{" "}
  1259. "]} then {
  1260.         message "accent set"
  1261.     } else {
  1262.         message "enter single character"
  1263. proc {
  1264. } {} {
  1265.     if {[wrapObject "\\\"{" "}
  1266. "]} then {
  1267.         message "accent set"
  1268.     } else {
  1269.         message "enter single character"
  1270. proc {
  1271. } {} {
  1272.     if {[wrapObject "\\~{" "}
  1273. "]} then {
  1274.         message "accent set"
  1275.     } else {
  1276.         message "enter single character"
  1277. proc {
  1278. } {} {insertObject "\\c\{c\}"}
  1279. proc {
  1280. } {} {insertObject "\\c\{C\}"}
  1281. proc {
  1282. } {} {insertObject "\\oe"}
  1283. proc {
  1284. } {} {insertObject "\\OE"}
  1285. proc {
  1286. } {} {insertObject "\\ae"}
  1287. proc {
  1288. } {} {insertObject "\\AE"}
  1289. proc {
  1290. } {} {insertObject "\\aa"}
  1291. proc {
  1292. } {} {insertObject "\\AA"}
  1293. proc {
  1294. } {} {insertObject "\\o"}
  1295. proc {
  1296. } {} {insertObject "\\O"}
  1297. proc {
  1298. } {} {insertObject "\\ss"}
  1299. proc {
  1300. } {} {insertObject "?`"}
  1301. proc {
  1302. } {} {insertObject "!`"}
  1303. #--------------------------------------------------------------------------
  1304. # Environments:
  1305. #--------------------------------------------------------------------------
  1306. proc enumerate {} {
  1307.     global promptNoisily useStatusBar
  1308.     set envName "enumerate"
  1309.     if {$promptNoisily && $useStatusBar} {beep}
  1310.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1311.     if {$numberItems == "cancel"} then {
  1312.         return
  1313.     } elseif {![isPositiveInteger $numberItems]} then {
  1314.         beep
  1315.         message "invalid input:  unsigned, postive integer required"
  1316.         return
  1317.     if {$numberItems} then {
  1318.         set body "\t\\item  
  1319.         for {set i 1} {$i < $numberItems} {incr i} {
  1320.             append body "\r\r\t\\item  
  1321.         append body "\r"
  1322.     } else {
  1323.         set body "\t
  1324.     if {[insertEnvironment $envName "" $body]} then {
  1325.         nextTabStop
  1326.         message "type first item"
  1327. proc itemize {} {
  1328.     global promptNoisily useStatusBar
  1329.     set envName "itemize"
  1330.     if {$promptNoisily && $useStatusBar} {beep}
  1331.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1332.     if {$numberItems == "cancel"} then {
  1333.         return
  1334.     } elseif {![isPositiveInteger $numberItems]} then {
  1335.         beep
  1336.         message "invalid input:  unsigned, postive integer required"
  1337.         return
  1338.     if {$numberItems} then {
  1339.         set body "\t\\item  
  1340.         for {set i 1} {$i < $numberItems} {incr i} {
  1341.             append body "\r\r\t\\item  
  1342.         append body "\r"
  1343.     } else {
  1344.         set body "\t
  1345.     if {[insertEnvironment $envName "" $body]} then {
  1346.         nextTabStop
  1347.         message "type first item"
  1348. proc description {} {
  1349.     global promptNoisily useStatusBar
  1350.     set envName "description"
  1351.     if {$promptNoisily && $useStatusBar} {beep}
  1352.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1353.     if {$numberItems == "cancel"} then {
  1354.         return
  1355.     } elseif {![isPositiveInteger $numberItems]} then {
  1356.         beep
  1357.         message "invalid input:  unsigned, postive integer required"
  1358.         return
  1359.     if {$numberItems} then {
  1360.         set body "\t\\item\[
  1361.         for {set i 1} {$i < $numberItems} {incr i} {
  1362.             append body "\r\r\t\\item\[
  1363.         append body "\r"
  1364.     } else {
  1365.         set body "\t
  1366.     if {[insertEnvironment $envName "" $body]} then {
  1367.         nextTabStop
  1368.         message "type first item label"
  1369. proc thebibliography {} {
  1370.     global promptNoisily useStatusBar
  1371.     set envName "thebibliography"
  1372.     if {$promptNoisily && $useStatusBar} {beep}
  1373.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1374.     if {$numberItems == "cancel"} then {
  1375.         return
  1376.     } elseif {![isPositiveInteger $numberItems]} then {
  1377.         beep
  1378.         message "invalid input:  unsigned, postive integer required"
  1379.         return
  1380.     set arg "{9}"
  1381.     if {$numberItems} then {
  1382.         if {$numberItems > 9} then {set arg "{99}"}
  1383.         set body "\t\\bibitem{
  1384.         for {set i 1} {$i < $numberItems} {incr i} {
  1385.             append body "\r\r\t\\bibitem{
  1386.         append body "\r"
  1387.     } else {
  1388.         set body "\t
  1389.     if {[insertEnvironment $envName $arg $body]} then {
  1390.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(9)+} [getPos]]
  1391.         eval select $searchResult
  1392.         message "Change the length of the key field?"
  1393. proc slide {} { doWrapEnvironment "slide" }
  1394. proc overlay {} { doWrapEnvironment "overlay" }
  1395. proc note {} { doWrapEnvironment "note" }
  1396. # proc figure {} {
  1397. #     global TeXmodeVars
  1398. #     set envName "figure"
  1399. #     set envArg "tbp"
  1400. #     set arg "\[$envArg\]"
  1401. #     set theIndentation [getIndentation [getPos]]
  1402. #     append arg "\r$theIndentation\t\\centering"
  1403. #     set body ""
  1404. #     if { $TeXmodeVars(useBoxMacro) } then {
  1405. #         set defaultMacro [car $TeXmodeVars(boxMacroNames)]
  1406. #         if { $defaultMacro == "" } {
  1407. #             append body "\t
  1408. #         } else {
  1409. #             set restOfMacros [cdr $TeXmodeVars(boxMacroNames)]
  1410. #             if { ![llength $restOfMacros] } {
  1411. #                 append body "\t\\$defaultMacro{
  1412. #             } else {
  1413. #                 set cmd [list prompt "Choose a boxMacro:"]
  1414. #                 lappend cmd $defaultMacro "" 
  1415. #                 foreach boxMacroName $TeXmodeVars(boxMacroNames) {
  1416. #                     lappend cmd $boxMacroName
  1417. #                 }
  1418. #                 catch $cmd macro
  1419. #                 if {$macro != "cancel"} then {
  1420. #                     append body "\t\\$macro{
  1421. #                 } else {
  1422. #                     message "operation canceled"
  1423. #                     return
  1424. #                 }
  1425. #             }
  1426. #         }
  1427. #     append body "\t\\caption{
  1428. #     append body "\t\\label{
  1429. #     if { $TeXmodeVars(useBoxMacro) } then {
  1430. #         if {![insertEnvironment $envName $arg $body]} then {return}
  1431. #     } else {
  1432. #         wrapEnvironment $envName $arg $body
  1433. #     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1434. #     eval select $searchResult
  1435. #     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1436. proc figure {} {
  1437.     global TeXmodeVars
  1438.     set envName "figure"
  1439.     set envArg "tbp"
  1440.     set arg "\[$envArg\]"
  1441.     set theIndentation [getIndentation [getPos]]
  1442.     append arg "\r$theIndentation\t\\centering"
  1443.     set body ""
  1444.     set macro [car $TeXmodeVars(boxMacroNames)]
  1445.     if { $macro != "" } {
  1446.         set restOfMacros [cdr $TeXmodeVars(boxMacroNames)]
  1447.         if { ![llength $restOfMacros] } {
  1448.             append body "\t\\$macro{
  1449.         } else {
  1450.             set cmd [list prompt "Choose a box macro:"]
  1451.             lappend cmd $macro "" 
  1452.             foreach boxMacroName $TeXmodeVars(boxMacroNames) {
  1453.                 lappend cmd $boxMacroName
  1454.             catch $cmd macro
  1455.             if {$macro == "cancel"} then {
  1456.                 message "operation canceled"
  1457.                 return
  1458.             } elseif {$macro == ""} then {
  1459.                 # do nothing
  1460.             } else {
  1461.                 append body "\t\\$macro{
  1462.     append body "\t\\caption{
  1463.     append body "\t\\label{
  1464.     if { $macro == "" } then {
  1465.         wrapEnvironment $envName $arg $body
  1466.     } else {
  1467.         if {![insertEnvironment $envName $arg $body]} then {return}
  1468.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1469.     eval select $searchResult
  1470.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1471. proc table {} {
  1472.     set envName "table"
  1473.     set envArg "tbp"
  1474.     set arg "\[$envArg\]"
  1475.     set theIndentation [getIndentation [getPos]]
  1476.     append arg "\r$theIndentation\t\\centering"
  1477.     # The following statement puts the caption at the top:
  1478.     append arg "\r$theIndentation\t\\caption{
  1479.     # The following statement puts the caption at the bottom:
  1480. #     set body "\t\\caption{
  1481.     append body "\t\\label{
  1482.     wrapEnvironment $envName $arg $body
  1483.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1484.     eval select $searchResult
  1485.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1486. proc buildRow {jmax} {
  1487.     set txt "
  1488.     for {set j 1} {$j < $jmax} {incr j} {
  1489.         append txt " & 
  1490.     return $txt
  1491. proc tabular {} {
  1492.     global promptNoisily useStatusBar
  1493.     set envName "tabular"
  1494.     if {$promptNoisily && $useStatusBar} {beep}
  1495.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1496.     if {$numberRows == "cancel"} then {
  1497.         return
  1498.     } elseif {![isPositiveInteger $numberRows]} then {
  1499.         beep
  1500.         message "invalid input:  unsigned, postive integer required"
  1501.         return
  1502.     if {$promptNoisily && $useStatusBar} {beep}
  1503.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  1504.     if {$numberCols == "cancel"} then {
  1505.         return
  1506.     } elseif {![isPositiveInteger $numberCols]} then {
  1507.         beep
  1508.         message "invalid input:  unsigned, postive integer required"
  1509.         return
  1510.     set arg "{|"
  1511.     for {set j 1} {$j <= $numberCols} {incr j} {
  1512.         append arg "c|"
  1513.     append arg "}"
  1514.     set body "\t\\hline\r"
  1515.     for {set i 1} {$i <= $numberRows} {incr i} {
  1516.         append body "\t[buildRow $numberCols]"
  1517.         append body "  \\\\\r\t\\hline\r"
  1518.     if {[insertEnvironment $envName $arg $body]} then {
  1519.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(c|\|)+} [getPos]]
  1520.         select [lindex $searchResult 0] [lindex $searchResult 1]
  1521.         message "Modify this argument?"
  1522. proc verbatim {} { doWrapEnvironment "verbatim" }
  1523. proc quote {} { doWrapEnvironment "quote" }
  1524. proc quotation {} { doWrapEnvironment "quotation" }
  1525. proc verse {} { doWrapEnvironment "verse" }
  1526. proc flushleft {} { doWrapEnvironment "flushleft" }
  1527. proc center {} { doWrapEnvironment "center" }
  1528. proc flushright {} { doWrapEnvironment "flushright" }
  1529. proc general {} {
  1530.     catch {prompt "What environment?" ""} environmentName
  1531.     if {$environmentName != "cancel"} {
  1532.         doWrapEnvironment "$environmentName"
  1533. #--------------------------------------------------------------------------
  1534. # Boxes:
  1535. #--------------------------------------------------------------------------
  1536. proc mbox {} {
  1537.     if {[wrapObject "\\mbox{" "}
  1538. "]} then {
  1539.         message "mbox set"
  1540.     } else {
  1541.         message "enter text"
  1542. proc makebox {} {
  1543.     if {[wrapObject "\\makebox\[
  1544. \]{" "}
  1545. "]} then {
  1546.         message "makebox set; enter the width and position"
  1547.     } else {
  1548.         message "enter the width and position of the makebox, then the text"
  1549. proc fbox {} {
  1550.     if {[wrapObject "\\fbox{" "}
  1551. "]} then {
  1552.         message "fbox set"
  1553.     } else {
  1554.         message "enter text"
  1555. proc framebox {} {
  1556.     if {[wrapObject "\\framebox\[
  1557. \]{" "}
  1558. "]} then {
  1559.         message "framebox set; enter the width and position"
  1560.     } else {
  1561.         message "enter the width and position of the framebox, then the text"
  1562. proc newsavebox {} {
  1563.     if {[wrapObject "\\newsavebox{" "}
  1564. "]} then {
  1565.         message "newsavebox defined"
  1566.     } else {
  1567.         message "enter the command name of the sbox or savebox"
  1568. proc sbox {} {
  1569.     if {[wrapObject "\\sbox{
  1570. }{" "}
  1571. "]} then {
  1572.         message "sbox set; enter the command name"
  1573.     } else {
  1574.         message "enter the command name of the sbox, then the text"
  1575. proc savebox {} {
  1576.     if {[wrapObject "\\savebox{
  1577. \]{" "}
  1578. "]} then {
  1579.         message "savebox set; enter the command name"
  1580.     } else {
  1581.         message "enter the command name of the savebox"
  1582. proc usebox {} {
  1583.     if {[wrapObject "\\usebox{" "}
  1584. "]} then {
  1585.         message "usebox declared"
  1586.     } else {
  1587.         message "enter the command name of the sbox or savebox"
  1588. proc raisebox {} {
  1589.     if {[wrapObject "\\raisebox{
  1590. \]{" "}
  1591. "]} then {
  1592.         message "raisebox set; enter the displacement"
  1593.     } else {
  1594.         message "enter the displacement of the raisebox"
  1595. proc parbox {} {
  1596.     if {[wrapObject "\\parbox\[
  1597. \}{" "}
  1598. "]} then {
  1599.         message "parbox set; enter the position and width"
  1600.     } else {
  1601.         message "enter the position \[b|c|t\] and width of the parbox, then the text"
  1602. proc minipage {} {
  1603.     set arg "\[
  1604.     wrapEnvironment "minipage" $arg ""
  1605.     nextTabStop
  1606.     message "enter the position \[b|c|t\] of the minipage, then the width"
  1607. proc rule {} {
  1608.     insertObject "\\rule\[
  1609.     nthTabStop -4
  1610.     message "enter the displacement of the rule, then width and height"
  1611. #--------------------------------------------------------------------------
  1612. # Misc:
  1613. #--------------------------------------------------------------------------
  1614. proc verb {} {
  1615.     if {[wrapObject "\\verb|" "|
  1616. "]} then {
  1617.         message "verbatim text set"
  1618.     } else {
  1619.         message "enter verbatim text"
  1620. proc footnote {} {
  1621.     if {[wrapObject "\\footnote{" "}
  1622. "]} then {
  1623.         message "footnote set"
  1624.     } else {
  1625.         message "enter footnote"
  1626. proc marginalNote {} {
  1627.     if {[wrapObject "\\marginpar{" "}
  1628. "]} then {
  1629.         message "marginal note set"
  1630.     } else {
  1631.         message "enter marginal note"
  1632. proc label {} {
  1633.     if {[wrapObject "\\label{" "}
  1634. "]} then {
  1635.         message "label defined"
  1636.     } else {
  1637.         message "enter label"
  1638. proc ref {} { 
  1639.     TeXRefCompletion "ref"
  1640. proc pageref {} { 
  1641.     TeXRefCompletion "pageref"
  1642. proc cite {} {
  1643.     if {[wrapObject "\\cite{" "}
  1644. "]} then {
  1645.         message "citation made"
  1646.     } else {
  1647.         message "enter citation key"
  1648. proc nocite {} {
  1649.     if {[wrapObject "\\nocite{" "}
  1650. "]} then {
  1651.         message "citation added to the list"
  1652.     } else {
  1653.         message "enter citation key"
  1654. # Insert an \item or a \bibitem, depending on the context.
  1655. proc insertItem {} {
  1656.     set command [eval getText [searchEnvironment]]
  1657.     set environment [extractCommandArg $command]
  1658.     switch $environment {
  1659.         "itemize" {
  1660.             set text "\\item  
  1661.         "enumerate" {
  1662.             set text "\\item  
  1663.         "description" {
  1664.             set text "\\item\[
  1665.         "thebibliography" {
  1666.             set text "\\bibitem{
  1667.         default {
  1668.             beep
  1669.             message "insertItem: cursor in $environment environment"
  1670.             return
  1671.     set pos [getPos]
  1672.     # Indentation should mirror that of an existing \item
  1673.     # (if it exists)
  1674.     insertText [openingCarriageReturn]$text
  1675.     goto $pos
  1676.     nextTabStop
  1677. proc quotes {} {
  1678.     if {[wrapObject "`" "'
  1679. "]} then {
  1680.         message "text quoted"
  1681.     } else {
  1682.         message "enter text"
  1683. proc dblQuotes {} {
  1684.     if {[wrapObject "``" "''
  1685. "]} then {
  1686.         message "text double quoted"
  1687.     } else {
  1688.         message "enter text"
  1689. proc ldots {} {insertObject "\\ldots"}
  1690. proc {en-dash} {} {insertObject "--"}
  1691. proc {em-dash} {} {insertObject "---"}
  1692. proc texLogo {} {insertObject "\\TeX"}
  1693. proc latexLogo {} {insertObject "\\LaTeX"}
  1694. proc latex2eLogo {} {insertObject "\\LaTeXe"}
  1695. proc today {} {insertObject "\\today"}
  1696. proc dag {} {insertObject "\\dag"}
  1697. proc ddag {} {insertObject "\\ddag"}
  1698. proc sectionMark {} {insertObject "\\S"}
  1699. proc paragraphMark {} {insertObject "\\P"}
  1700. proc copyright {} {insertObject "\\copyright"}
  1701. proc pounds {} {insertObject "\\pounds"}
  1702. #############################################################################
  1703. # Math Mode Macros
  1704. #############################################################################
  1705. #--------------------------------------------------------------------------
  1706. # Math Modes:
  1707. #--------------------------------------------------------------------------
  1708. proc texMath {} {
  1709.     checkMathMode "texMath" 0
  1710.     if {[wrapObject "$" "$
  1711. "]} then {
  1712.         message "formula set"
  1713.     } else {
  1714.         message "enter formula"
  1715. proc texDisplaymath {} {
  1716.     checkMathMode "texDisplaymath" 0
  1717.     if {[wrapObject "$$" "$$
  1718. "]} then {
  1719.         message "displayed formula set"
  1720.     } else {
  1721.         message "enter displayed formula"
  1722. proc latexMath {} {
  1723.     checkMathMode "latexMath" 0
  1724.     if {[wrapObject "\\( " " \\)
  1725. "]} then {
  1726.         message "formula set"
  1727.     } else {
  1728.         message "enter formula"
  1729. proc latexDisplaymath {} {
  1730.     checkMathMode "latexDisplaymath" 0
  1731.     if {[wrapObject "\\\[ " " \\\]
  1732. "]} then {
  1733.         message "displayed formula set"
  1734.     } else {
  1735.         message "enter displayed formula"
  1736. #--------------------------------------------------------------------------
  1737. # Math Style:
  1738. #--------------------------------------------------------------------------
  1739. proc mathit {} {
  1740.     checkMathMode "mathit" 1
  1741.     if {[wrapObject "\\mathit{" "}
  1742. "]} then {
  1743.         message "selected text is math italic"
  1744.     } else {
  1745.         message "enter text to be math italic"
  1746. proc mathrm {} {
  1747.     checkMathMode "mathrm" 1
  1748.     if {[wrapObject "\\mathrm{" "}
  1749. "]} then {
  1750.         message "selected text is math roman"
  1751.     } else {
  1752.         message "enter text to be math roman"
  1753. proc mathbf {} {
  1754.     checkMathMode "mathbf" 1
  1755.     if {[wrapObject "\\mathbf{" "}
  1756. "]} then {
  1757.         message "selected text is math bold"
  1758.     } else {
  1759.         message "enter text to be math bold"
  1760. proc mathsf {} {
  1761.     checkMathMode "mathsf" 1
  1762.     if {[wrapObject "\\mathsf{" "}
  1763. "]} then {
  1764.         message "selected text is math sans serif"
  1765.     } else {
  1766.         message "enter text to be math sans serif"
  1767. proc mathtt {} {
  1768.     checkMathMode "mathtt" 1
  1769.     if {[wrapObject "\\mathtt{" "}
  1770. "]} then {
  1771.         message "selected text is math typewriter"
  1772.     } else {
  1773.         message "enter text to be math typewriter"
  1774. proc mathcal {} {
  1775.     checkMathMode "mathcal" 1
  1776.     # Allow upper-case arguments only:
  1777.     if {[isSelection] && ![isUppercase]} then {
  1778.         alertnote "argument to \\mathcal must be uppercase"
  1779.         return
  1780.     if {[wrapObject "\\mathcal{" "}
  1781. "]} then {
  1782.         message "selected text is calligraphic"
  1783.     } else {
  1784.         message "enter text to be calligraphic (UPPERCASE letters only)"
  1785. proc displaystyle {} {
  1786.     checkMathMode "displaystyle" 1
  1787.     if {[wrapObject "{\\displaystyle " "}
  1788. "]} then {
  1789.         message "displaystyle set"
  1790.     } else {
  1791.         message "enter displaystyle text"
  1792. proc textstyle {} {
  1793.     checkMathMode "textstyle" 1
  1794.     if {[wrapObject "{\\textstyle " "}
  1795. "]} then {
  1796.         message "textstyle set"
  1797.     } else {
  1798.         message "enter textstyle text"
  1799. proc scriptstyle {} {
  1800.     checkMathMode "scriptstyle" 1
  1801.     if {[wrapObject "{\\scriptstyle " "}
  1802. "]} then {
  1803.         message "scriptstyle set"
  1804.     } else {
  1805.         message "enter scriptstyle text"
  1806. proc scriptscriptstyle {} {
  1807.     checkMathMode "scriptscriptstyle" 1
  1808.     if {[wrapObject "{\\scriptscriptstyle " "}
  1809. "]} then {
  1810.         message "scriptscriptstyle set"
  1811.     } else {
  1812.         message "enter scriptscriptstyle text"
  1813. #--------------------------------------------------------------------------
  1814. # Math Environments:
  1815. #--------------------------------------------------------------------------
  1816. proc math {} { checkMathMode "math" 0; doWrapEnvironment "math" }
  1817. proc displaymath {} {
  1818.     checkMathMode "displaymath" 0
  1819.     global TeXmodeVars
  1820.     if { $TeXmodeVars(useBrackets) } {
  1821.         doWrapStructure {\[} {} {\]}
  1822.     } else {
  1823.         doWrapEnvironment "displaymath"
  1824. proc equation {} {
  1825.     checkMathMode "equation" 0
  1826.     set envName "equation"
  1827.     set body "\t\\label{
  1828.     if {[wrapEnvironment $envName "" $body]} then {
  1829.         set msgText "equation wrapped"
  1830.     } else {
  1831.         set msgText "enter equation"
  1832.     nextTabStop
  1833.     message $msgText
  1834. proc eqnarrayStar {} {
  1835.     global promptNoisily useStatusBar
  1836.     checkMathMode "eqnarrayStar" 0
  1837.     set envName "eqnarray*"
  1838.     if {$promptNoisily && $useStatusBar} {beep}
  1839.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1840.     if {$numberRows == "cancel"} then {
  1841.         return
  1842.     } elseif {![isPositiveInteger $numberRows]} then {
  1843.         beep
  1844.         message "invalid input:  unsigned, postive integer required"
  1845.         return
  1846.     set row "\t[buildRow 3]"
  1847.     for {set i 1} {$i < $numberRows} {incr i} {
  1848.         append body $row
  1849.         append body "  \\\\\r"
  1850.     append body $row
  1851.     append body "\r"
  1852.     if {[insertEnvironment $envName "" $body]} then {
  1853.         nextTabStop
  1854.         message "type first item"
  1855. proc eqnarray {} {
  1856.     global promptNoisily useStatusBar
  1857.     checkMathMode "eqnarray" 0
  1858.     set envName "eqnarray"
  1859.     if {$promptNoisily && $useStatusBar} {beep}
  1860.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1861.     if {$numberRows == "cancel"} then {
  1862.         return
  1863.     } elseif {![isPositiveInteger $numberRows]} then {
  1864.         beep
  1865.         message "invalid input:  unsigned, postive integer required"
  1866.         return
  1867.     set row "\t[buildRow 3]\r\t\\label{
  1868.     for {set i 1} {$i < $numberRows} {incr i} {
  1869.         append body $row
  1870.         append body "  \\\\\r"
  1871.     append body $row
  1872.     append body "\r"
  1873.     if {[insertEnvironment $envName "" $body]} then {
  1874.         nextTabStop
  1875.         message "type first item"
  1876. proc myArray {} {
  1877.     global promptNoisily useStatusBar
  1878.     checkMathMode "myArray" 1
  1879.     set envName "array"
  1880.     if {$promptNoisily && $useStatusBar} {beep}
  1881.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1882.     if {$numberRows == "cancel"} then {
  1883.         return
  1884.     } elseif {![isPositiveInteger $numberRows]} then {
  1885.         beep
  1886.         message "invalid input:  unsigned, postive integer required"
  1887.         return
  1888.     if {$promptNoisily && $useStatusBar} {beep}
  1889.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  1890.     if {$numberCols == "cancel"} then {
  1891.         return
  1892.     } elseif {![isPositiveInteger $numberCols]} then {
  1893.         beep
  1894.         message "invalid input:  unsigned, postive integer required"
  1895.         return
  1896.     set arg "{"
  1897.     for {set j 1} {$j <= $numberCols} {incr j} {
  1898.         append arg "c"
  1899.     append arg "}"
  1900.     set row "\t[buildRow $numberCols]"
  1901.     for {set i 1} {$i < $numberRows} {incr i} {
  1902.         append body $row
  1903.         append body "  \\\\\r"
  1904.     append body $row
  1905.     append body "\r"
  1906.     if {[insertEnvironment $envName $arg $body]} then {
  1907.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {c+} [getPos]]
  1908.         select [lindex $searchResult 0] [lindex $searchResult 1]
  1909.         message "Modify this argument?"
  1910. #--------------------------------------------------------------------------
  1911. # Formulas:
  1912. #--------------------------------------------------------------------------
  1913. proc subscript {} {
  1914.     checkMathMode "subscript" 1
  1915.     if {[wrapObject "_{" "}
  1916. "]} then {
  1917.         message "subscript set"
  1918.     } else {
  1919.         message "enter subscript"
  1920. proc superscript {} {
  1921.     checkMathMode "superscript" 1
  1922.     if {[wrapObject "^{" "}
  1923. "]} then {
  1924.         message "superscript set"
  1925.     } else {
  1926.         message "enter superscript"
  1927. proc fraction {} {
  1928.     checkMathMode "fraction" 1
  1929.     set currentPos [getPos]
  1930.     if {[isSelection]} then {
  1931.         set selection [getSelect]
  1932.         set args [split $selection /]
  1933.         set len [llength $args]
  1934.         deleteText $currentPos [selEnd]
  1935.         if {$len == 1} then {
  1936.             insertObject "\\frac{$selection}{
  1937.             goto $currentPos
  1938.             nextTabStop
  1939.             message "enter denominator"
  1940.         } else {
  1941.             set firstArg [lindex $args 0]
  1942.             set restArgs [lrange $args 1 [expr $len-1]]
  1943.             insertObject "\\frac{$firstArg}{[join $restArgs /]}"
  1944.             if {$len > 2} {message "beware of multiple /"}
  1945.     } else {
  1946.         insertObject "\\frac{
  1947.         goto $currentPos
  1948.         nextTabStop
  1949.         message "enter numerator"
  1950. proc squareRoot {} {
  1951.     checkMathMode "squareRoot" 1
  1952.     if {[wrapObject "\\sqrt{" "}
  1953. "]} then {
  1954.         message "square root set"
  1955.     } else {
  1956.         message "enter formula"
  1957. proc nthRoot {} {
  1958.     checkMathMode "nthRoot" 1
  1959.     if {[wrapObject "\\sqrt\[
  1960. \]{" "}
  1961. "]} then {
  1962.         message "enter root"
  1963.     } else {
  1964.         message "enter root, then formula"
  1965. proc oneParameter {} {
  1966.     checkMathMode "oneParameter" 1
  1967.     if {[wrapObject "\\
  1968. {" "}
  1969. "]} then {
  1970.         message "enter command name"
  1971.     } else {
  1972.         message "enter command name, press <Tab>, enter argument"
  1973. proc twoParameters {} {
  1974.     checkMathMode "twoParameters" 1
  1975.     if {[wrapObject "\\
  1976. {" "}{
  1977. "]} then {
  1978.         message "enter command name"
  1979.     } else {
  1980.         message "enter command name, press <Tab>, enter argument, etc."
  1981. #--------------------------------------------------------------------------
  1982. # Greek:
  1983. #--------------------------------------------------------------------------
  1984. proc alpha {} {checkMathMode "alpha" 1; insertObject "\\alpha"}
  1985. proc beta {} {checkMathMode "beta" 1; insertObject "\\beta"}
  1986. proc gamma {} {checkMathMode "gamma" 1; insertObject "\\gamma"}
  1987. proc delta {} {checkMathMode "delta" 1; insertObject "\\delta"}
  1988. proc epsilon {} {checkMathMode "epsilon" 1; insertObject "\\epsilon"}
  1989. proc zeta {} {checkMathMode "zeta" 1; insertObject "\\zeta"}
  1990. proc eta {} {checkMathMode "eta" 1; insertObject "\\eta"}
  1991. proc theta {} {checkMathMode "theta" 1; insertObject "\\theta"}
  1992. proc iota {} {checkMathMode "iota" 1; insertObject "\\iota"}
  1993. proc kappa {} {checkMathMode "kappa" 1; insertObject "\\kappa"}
  1994. proc lambda {} {checkMathMode "lambda" 1; insertObject "\\lambda"}
  1995. proc mu {} {checkMathMode "mu" 1; insertObject "\\mu"}
  1996. proc nu {} {checkMathMode "nu" 1; insertObject "\\nu"}
  1997. proc xi {} {checkMathMode "xi" 1; insertObject "\\xi"}
  1998. proc omicron {} {checkMathMode "omicron" 1; insertObject "o"}
  1999. proc pi {} {checkMathMode "pi" 1; insertObject "\\pi"}
  2000. proc rho {} {checkMathMode "rho" 1; insertObject "\\rho"}
  2001. proc sigma {} {checkMathMode "sigma" 1; insertObject "\\sigma"}
  2002. proc tau {} {checkMathMode "tau" 1; insertObject "\\tau"}
  2003. proc upsilon {} {checkMathMode "upsilon" 1; insertObject "\\upsilon"}
  2004. proc phi {} {checkMathMode "phi" 1; insertObject "\\phi"}
  2005. proc chi {} {checkMathMode "chi" 1; insertObject "\\chi"}
  2006. proc psi {} {checkMathMode "psi" 1; insertObject "\\psi"}
  2007. proc omega {} {checkMathMode "omega" 1; insertObject "\\omega"}
  2008. proc Gamma {} {checkMathMode "Gamma" 1; insertObject "\\Gamma"}
  2009. proc Delta {} {checkMathMode "Delta" 1; insertObject "\\Delta"}
  2010. proc Theta {} {checkMathMode "Theta" 1; insertObject "\\Theta"}
  2011. proc Lambda {} {checkMathMode "Lambda" 1; insertObject "\\Lambda"}
  2012. proc Xi {} {checkMathMode "Xi" 1; insertObject "\\Xi"}
  2013. proc Pi {} {checkMathMode "Pi" 1; insertObject "\\Pi"}
  2014. proc Sigma {} {checkMathMode "Sigma" 1; insertObject "\\Sigma"}
  2015. proc Upsilon {} {checkMathMode "Upsilon" 1; insertObject "\\Upsilon"}
  2016. proc Phi {} {checkMathMode "Phi" 1; insertObject "\\Phi"}
  2017. proc Psi {} {checkMathMode "Psi" 1; insertObject "\\Psi"}
  2018. proc Omega {} {checkMathMode "Omega" 1; insertObject "\\Omega"}
  2019. proc varepsilon {} {checkMathMode "varepsilon" 1; insertObject "\\varepsilon"}
  2020. proc vartheta {} {checkMathMode "vartheta" 1; insertObject "\\vartheta"}
  2021. proc varpi {} {checkMathMode "varpi" 1; insertObject "\\varpi"}
  2022. proc varrho {} {checkMathMode "varrho" 1; insertObject "\\varrho"}
  2023. proc varsigma {} {checkMathMode "varsigma" 1; insertObject "\\varsigma"}
  2024. proc varphi {} {checkMathMode "varphi" 1; insertObject "\\varphi"}
  2025. #--------------------------------------------------------------------------
  2026. # Binary Ops:
  2027. #--------------------------------------------------------------------------
  2028. proc pm {} {checkMathMode "pm" 1; insertObject "\\pm"}
  2029. proc mp {} {checkMathMode "mp" 1; insertObject "\\mp"}
  2030. proc times {} {checkMathMode "times" 1; insertObject "\\times"}
  2031. proc div {} {checkMathMode "div" 1; insertObject "\\div"}
  2032. proc ast {} {checkMathMode "ast" 1; insertObject "\\ast"}
  2033. proc star {} {checkMathMode "star" 1; insertObject "\\star"}
  2034. proc circ {} {checkMathMode "circ" 1; insertObject "\\circ"}
  2035. proc bullet {} {checkMathMode "bullet" 1; insertObject "\\bullet"}
  2036. proc cdot {} {checkMathMode "cdot" 1; insertObject "\\cdot"}
  2037. proc cap {} {checkMathMode "cap" 1; insertObject "\\cap"}
  2038. proc cup {} {checkMathMode "cup" 1; insertObject "\\cup"}
  2039. proc uplus {} {checkMathMode "uplus" 1; insertObject "\\uplus"}
  2040. proc sqcap {} {checkMathMode "sqcap" 1; insertObject "\\sqcap"}
  2041. proc sqcup {} {checkMathMode "sqcup" 1; insertObject "\\sqcup"}
  2042. proc vee {} {checkMathMode "vee" 1; insertObject "\\vee"}
  2043. proc wedge {} {checkMathMode "wedge" 1; insertObject "\\wedge"}
  2044. proc setminus {} {checkMathMode "setminus" 1; insertObject "\\setminus"}
  2045. proc wr {} {checkMathMode "wr" 1; insertObject "\\wr"}
  2046. proc diamond {} {checkMathMode "diamond" 1; insertObject "\\diamond"}
  2047. proc bigtriangleup {} {
  2048.     checkMathMode "bigtriangleup" 1; insertObject "\\bigtriangleup"
  2049. proc bigtriangledown {} {
  2050.     checkMathMode "bigtriangledown" 1; insertObject "\\bigtriangledown"
  2051. proc triangleleft {} {
  2052.     checkMathMode "triangleleft" 1; insertObject "\\triangleleft"
  2053. proc triangleright {} {
  2054.     checkMathMode "triangleright" 1; insertObject "\\triangleright"
  2055. proc lhd {} {
  2056.     if {[isSymbolPackageLoaded]} then {
  2057.         checkMathMode "lhd" 1; insertObject "\\lhd"
  2058. proc rhd {} {
  2059.     if {[isSymbolPackageLoaded]} then {
  2060.         checkMathMode "rhd" 1; insertObject "\\rhd"
  2061. proc unlhd {} {
  2062.     if {[isSymbolPackageLoaded]} then {
  2063.         checkMathMode "unlhd" 1; insertObject "\\unlhd"
  2064. proc unrhd {} {
  2065.     if {[isSymbolPackageLoaded]} then {
  2066.         checkMathMode "unrhd" 1; insertObject "\\unrhd"
  2067. proc oplus {} {checkMathMode "oplus" 1; insertObject "\\oplus"}
  2068. proc ominus {} {checkMathMode "ominus" 1; insertObject "\\ominus"}
  2069. proc otimes {} {checkMathMode "otimes" 1; insertObject "\\otimes"}
  2070. proc oslash {} {checkMathMode "oslash" 1; insertObject "\\oslash"}
  2071. proc odot {} {checkMathMode "odot" 1; insertObject "\\odot"}
  2072. proc bigcirc {} {checkMathMode "bigcirc" 1; insertObject "\\bigcirc"}
  2073. proc dagger {} {checkMathMode "dagger" 1; insertObject "\\dagger"}
  2074. proc ddagger {} {checkMathMode "ddagger" 1; insertObject "\\ddagger"}
  2075. proc amalg {} {checkMathMode "amalg" 1; insertObject "\\amalg"}
  2076. #--------------------------------------------------------------------------
  2077. # Relations:
  2078. #--------------------------------------------------------------------------
  2079. proc leq {} {checkMathMode "leq" 1; insertObject "\\leq"}
  2080. proc prec {} {checkMathMode "prec" 1; insertObject "\\prec"}
  2081. proc preceq {} {checkMathMode "preceq" 1; insertObject "\\preceq"}
  2082. proc myLl {} {checkMathMode "myLl" 1; insertObject "\\ll"}
  2083. proc subset {} {checkMathMode "subset" 1; insertObject "\\subset"}
  2084. proc subseteq {} {checkMathMode "subseteq" 1; insertObject "\\subseteq"}
  2085. proc sqsubset {} {
  2086.     if {[isSymbolPackageLoaded]} then {
  2087.         checkMathMode "sqsubset" 1; insertObject "\\sqsubset"
  2088. proc sqsubseteq {} {checkMathMode "sqsubseteq" 1; insertObject "\\sqsubseteq"}
  2089. proc in {} {checkMathMode "in" 1; insertObject "\\in"}
  2090. proc vdash {} {checkMathMode "vdash" 1; insertObject "\\vdash"}
  2091. proc geq {} {checkMathMode "geq" 1; insertObject "\\geq"}
  2092. proc succ {} {checkMathMode "succ" 1; insertObject "\\succ"}
  2093. proc succeq {} {checkMathMode "succeq" 1; insertObject "\\succeq"}
  2094. proc gg {} {checkMathMode "gg" 1; insertObject "\\gg"}
  2095. proc supset {} {checkMathMode "supset" 1; insertObject "\\supset"}
  2096. proc supseteq {} {checkMathMode "supseteq" 1; insertObject "\\supseteq"}
  2097. proc sqsupset {} {
  2098.     if {[isSymbolPackageLoaded]} then {
  2099.         checkMathMode "sqsupset" 1; insertObject "\\sqsupset"
  2100. proc sqsupseteq {} {checkMathMode "sqsupseteq" 1; insertObject "\\sqsupseteq"}
  2101. proc ni {} {checkMathMode "ni" 1; insertObject "\\ni"}
  2102. proc dashv {} {checkMathMode "dashv" 1; insertObject "\\dashv"}
  2103. proc equiv {} {checkMathMode "equiv" 1; insertObject "\\equiv"}
  2104. proc sim {} {checkMathMode "sim" 1; insertObject "\\sim"}
  2105. proc simeq {} {checkMathMode "simeq" 1; insertObject "\\simeq"}
  2106. proc asymp {} {checkMathMode "asymp" 1; insertObject "\\asymp"}
  2107. proc approx {} {checkMathMode "approx" 1; insertObject "\\approx"}
  2108. proc cong {} {checkMathMode "cong" 1; insertObject "\\cong"}
  2109. proc neq {} {checkMathMode "neq" 1; insertObject "\\neq"}
  2110. proc doteq {} {checkMathMode "doteq" 1; insertObject "\\doteq"}
  2111. proc propto {} {checkMathMode "propto" 1; insertObject "\\propto"}
  2112. proc models {} {checkMathMode "models" 1; insertObject "\\models"}
  2113. proc perp {} {checkMathMode "perp" 1; insertObject "\\perp"}
  2114. proc mid {} {checkMathMode "mid" 1; insertObject "\\mid"}
  2115. proc parallel {} {checkMathMode "parallel" 1; insertObject "\\parallel"}
  2116. proc bowtie {} {checkMathMode "bowtie" 1; insertObject "\\bowtie"}
  2117. proc myJoin {} {
  2118.     if {[isSymbolPackageLoaded]} then {
  2119.         checkMathMode "myJoin" 1; insertObject "\\join"
  2120. proc smile {} {checkMathMode "smile" 1; insertObject "\\smile"}
  2121. proc frown {} {checkMathMode "frown" 1; insertObject "\\frown"}
  2122. #--------------------------------------------------------------------------
  2123. # Arrows:
  2124. #--------------------------------------------------------------------------
  2125. proc leftarrow {} {checkMathMode "leftarrow" 1; insertObject "\\leftarrow"}
  2126. proc Leftarrow {} {checkMathMode "Leftarrow" 1; insertObject "\\Leftarrow"}
  2127. proc rightarrow {} {checkMathMode "rightarrow" 1; insertObject "\\rightarrow"}
  2128. proc Rightarrow {} {checkMathMode "Rightarrow" 1; insertObject "\\Rightarrow"}
  2129. proc leftrightarrow {} {
  2130.     checkMathMode "leftrightarrow" 1; insertObject "\\leftrightarrow"
  2131. proc Leftrightarrow {} {
  2132.     checkMathMode "Leftrightarrow" 1; insertObject "\\Leftrightarrow"
  2133. proc mapsto {} {checkMathMode "mapsto" 1; insertObject "\\mapsto"}
  2134. proc hookleftarrow {} {
  2135.     checkMathMode "hookleftarrow" 1; insertObject "\\hookleftarrow"
  2136. proc leftharpoonup {} {
  2137.     checkMathMode "leftharpoonup" 1; insertObject "\\leftharpoonup"
  2138. proc leftharpoondown {} {
  2139.     checkMathMode "leftharpoondown" 1; insertObject "\\leftharpoondown"
  2140. proc rightleftharpoons {} {
  2141.     checkMathMode "rightleftharpoons" 1; insertObject "\\rightleftharpoons"
  2142. proc longleftarrow {} {
  2143.     checkMathMode "longleftarrow" 1; insertObject "\\longleftarrow"
  2144. proc Longleftarrow {} {
  2145.     checkMathMode "Longleftarrow" 1; insertObject "\\Longleftarrow"
  2146. proc longrightarrow {} {
  2147.     checkMathMode "longrightarrow" 1; insertObject "\\longrightarrow"
  2148. proc Longrightarrow {} {
  2149.     checkMathMode "Longrightarrow" 1; insertObject "\\Longrightarrow"
  2150. proc longleftrightarrow {} {
  2151.     checkMathMode "longleftrightarrow" 1; insertObject "\\longleftrightarrow"
  2152. proc Longleftrightarrow {} {
  2153.     checkMathMode "Longleftrightarrow" 1; insertObject "\\Longleftrightarrow"
  2154. proc longmapsto {} {checkMathMode "longmapsto" 1; insertObject "\\longmapsto"}
  2155. proc hookrightarrow {} {
  2156.     checkMathMode "hookrightarrow" 1; insertObject "\\hookrightarrow"
  2157. proc rightharpoonup {} {
  2158.     checkMathMode "rightharpoonup" 1; insertObject "\\rightharpoonup"
  2159. proc rightharpoondown {} {
  2160.     checkMathMode "rightharpoondown" 1; insertObject "\\rightharpoondown"
  2161. proc leadsto {} {
  2162.     if {[isSymbolPackageLoaded]} then {
  2163.         checkMathMode "leadsto" 1; insertObject "\\leadsto"
  2164. proc uparrow {} {checkMathMode "uparrow" 1; insertObject "\\uparrow"}
  2165. proc Uparrow {} {checkMathMode "Uparrow" 1; insertObject "\\Uparrow"}
  2166. proc downarrow {} {checkMathMode "downarrow" 1; insertObject "\\downarrow"}
  2167. proc Downarrow {} {checkMathMode "Downarrow" 1; insertObject "\\Downarrow"}
  2168. proc updownarrow {} {checkMathMode "updownarrow" 1; insertObject "\\updownarrow"}
  2169. proc Updownarrow {} {checkMathMode "Updownarrow" 1; insertObject "\\Updownarrow"}
  2170. proc nearrow {} {checkMathMode "nearrow" 1; insertObject "\\nearrow"}
  2171. proc searrow {} {checkMathMode "searrow" 1; insertObject "\\searrow"}
  2172. proc swarrow {} {checkMathMode "swarrow" 1; insertObject "\\swarrow"}
  2173. proc nwarrow {} {checkMathMode "nwarrow" 1; insertObject "\\nwarrow"}
  2174. #--------------------------------------------------------------------------
  2175. # Dots:
  2176. #--------------------------------------------------------------------------
  2177. proc cdots {} {checkMathMode "cdots" 1; insertObject "\\cdots"}
  2178. proc vdots {} {checkMathMode "vdots" 1; insertObject "\\vdots"}
  2179. proc ddots {} {checkMathMode "ddots" 1; insertObject "\\ddots"}
  2180. #--------------------------------------------------------------------------
  2181. # Symbols:
  2182. #--------------------------------------------------------------------------
  2183. proc aleph {} {checkMathMode "aleph" 1; insertObject "\\aleph"}
  2184. proc hbar {} {checkMathMode "hbar" 1; insertObject "\\hbar"}
  2185. proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
  2186. proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
  2187. proc ell {} {checkMathMode "ell" 1; insertObject "\\ell"}
  2188. proc wp {} {checkMathMode "wp" 1; insertObject "\\wp"}
  2189. proc Re {} {checkMathMode "Re" 1; insertObject "\\Re"}
  2190. proc Im {} {checkMathMode "Im" 1; insertObject "\\Im"}
  2191. proc mho {} {
  2192.     if {[isSymbolPackageLoaded]} then {
  2193.         checkMathMode "mho" 1; insertObject "\\mho"
  2194. proc prime {} {checkMathMode "prime" 1; insertObject "\\prime"}
  2195. proc emptyset {} {checkMathMode "emptyset" 1; insertObject "\\emptyset"}
  2196. proc nabla {} {checkMathMode "nabla" 1; insertObject "\\nabla"}
  2197. proc surd {} {checkMathMode "surd" 1; insertObject "\\surd"}
  2198. proc top {} {checkMathMode "top" 1; insertObject "\\top"}
  2199. proc bot {} {checkMathMode "bot" 1; insertObject "\\bot"}
  2200. # proc | {} {checkMathMode "|" 1; insertObject "\\|"}
  2201. proc angle {} {checkMathMode "angle" 1; insertObject "\\angle"}
  2202. proc forall {} {checkMathMode "forall" 1; insertObject "\\forall"}
  2203. proc exists {} {checkMathMode "exists" 1; insertObject "\\exists"}
  2204. proc neg {} {checkMathMode "neg" 1; insertObject "\\neg"}
  2205. proc flat {} {checkMathMode "flat" 1; insertObject "\\flat"}
  2206. proc natural {} {checkMathMode "natural" 1; insertObject "\\natural"}
  2207. proc sharp {} {checkMathMode "sharp" 1; insertObject "\\sharp"}
  2208. proc backslash {} {checkMathMode "backslash" 1; insertObject "\\backslash"}
  2209. proc partial {} {checkMathMode "partial" 1; insertObject "\\partial"}
  2210. proc infty {} {checkMathMode "infty" 1; insertObject "\\infty"}
  2211. proc Box {} {
  2212.     if {[isSymbolPackageLoaded]} then {
  2213.         checkMathMode "Box" 1; insertObject "\\Box"
  2214. proc Diamond {} {
  2215.     if {[isSymbolPackageLoaded]} then {
  2216.         checkMathMode "Diamond" 1; insertObject "\\Diamond"
  2217. proc triangle {} {checkMathMode "triangle" 1; insertObject "\\triangle"}
  2218. proc clubsuit {} {checkMathMode "clubsuit" 1; insertObject "\\clubsuit"}
  2219. proc diamondsuit {} {checkMathMode "diamondsuit" 1; insertObject "\\diamondsuit"}
  2220. proc heartsuit {} {checkMathMode "heartsuit" 1; insertObject "\\heartsuit"}
  2221. proc spadesuit {} {checkMathMode "spadesuit" 1; insertObject "\\spadesuit"}
  2222. #--------------------------------------------------------------------------
  2223. # Functions:
  2224. #--------------------------------------------------------------------------
  2225. proc arccos {} {checkMathMode "arccos" 1; insertObject "\\arccos"}
  2226. proc arcsin {} {checkMathMode "arcsin" 1; insertObject "\\arcsin"}
  2227. proc arctan {} {checkMathMode "arctan" 1; insertObject "\\arctan"}
  2228. proc arg {} {checkMathMode "arg" 1; insertObject "\\arg"}
  2229. proc cos {} {checkMathMode "cos" 1; insertObject "\\cos"}
  2230. proc cosh {} {checkMathMode "cosh" 1; insertObject "\\cosh"}
  2231. proc cot {} {checkMathMode "cot" 1; insertObject "\\cot"}
  2232. proc coth {} {checkMathMode "coth" 1; insertObject "\\coth"}
  2233. proc csc {} {checkMathMode "csc" 1; insertObject "\\csc"}
  2234. proc deg {} {checkMathMode "deg" 1; insertObject "\\deg"}
  2235. proc det {} {checkMathMode "det" 1; insertObject "\\det"}
  2236. proc dim {} {checkMathMode "dim" 1; insertObject "\\dim"}
  2237. proc exp {} {checkMathMode "exp" 1; insertObject "\\exp"}
  2238. proc gcd {} {checkMathMode "gcd" 1; insertObject "\\gcd"}
  2239. proc hom {} {checkMathMode "hom" 1; insertObject "\\hom"}
  2240. # proc inf {} {checkMathMode "inf" 1; insertObject "\\inf"}
  2241. proc inf {} {
  2242.     checkMathMode "inf" 1
  2243.     if {[wrapObject "\\inf_{" "}
  2244. "]} then {
  2245.         message "limit set"
  2246.     } else {
  2247.         message "enter limit"
  2248. proc ker {} {checkMathMode "ker" 1; insertObject "\\ker"}
  2249. proc lg {} {checkMathMode "lg" 1; insertObject "\\lg"}
  2250. # proc lim {} {checkMathMode "lim" 1; insertObject "\\lim"}
  2251. proc lim {} {
  2252.     checkMathMode "lim" 1
  2253.     if {[wrapObject "\\lim_{" "}
  2254. "]} then {
  2255.         message "limit set"
  2256.     } else {
  2257.         message "enter limit"
  2258. # proc liminf {} {checkMathMode "liminf" 1; insertObject "\\liminf"}
  2259. proc liminf {} {
  2260.     checkMathMode "liminf" 1
  2261.     if {[wrapObject "\\liminf_{" "}
  2262. "]} then {
  2263.         message "limit set"
  2264.     } else {
  2265.         message "enter limit"
  2266. # proc limsup {} {checkMathMode "limsup" 1; insertObject "\\limsup"}
  2267. proc limsup {} {
  2268.     checkMathMode "limsup" 1
  2269.     if {[wrapObject "\\limsup_{" "}
  2270. "]} then {
  2271.         message "limit set"
  2272.     } else {
  2273.         message "enter limit"
  2274. proc ln {} {checkMathMode "ln" 1; insertObject "\\ln"}
  2275. proc log {} {checkMathMode "log" 1; insertObject "\\log"}
  2276. # proc max {} {checkMathMode "max" 1; insertObject "\\max"}
  2277. proc max {} {
  2278.     checkMathMode "max" 1
  2279.     if {[wrapObject "\\max_{" "}
  2280. "]} then {
  2281.         message "limit set"
  2282.     } else {
  2283.         message "enter limit"
  2284. # proc min {} {checkMathMode "min" 1; insertObject "\\min"}
  2285. proc min {} {
  2286.     checkMathMode "min" 1
  2287.     if {[wrapObject "\\min_{" "}
  2288. "]} then {
  2289.         message "limit set"
  2290.     } else {
  2291.         message "enter limit"
  2292. proc Pr {} {checkMathMode "Pr" 1; insertObject "\\Pr"}
  2293. proc sec {} {checkMathMode "sec" 1; insertObject "\\sec"}
  2294. proc sin {} {checkMathMode "sin" 1; insertObject "\\sin"}
  2295. proc sinh {} {checkMathMode "sinh" 1; insertObject "\\sinh"}
  2296. # proc sup {} {checkMathMode "sup" 1; insertObject "\\sup"}
  2297. proc sup {} {
  2298.     checkMathMode "sup" 1
  2299.     if {[wrapObject "\\sup_{" "}
  2300. "]} then {
  2301.         message "limit set"
  2302.     } else {
  2303.         message "enter limit"
  2304. proc tan {} {checkMathMode "tan" 1; insertObject "\\tan"}
  2305. proc tanh {} {checkMathMode "tanh" 1; insertObject "\\tanh"}
  2306. proc bmod {} {checkMathMode "bmod" 1; insertObject "\\bmod"}
  2307. proc pmod {} {
  2308.     checkMathMode "pmod" 1
  2309.     if {[wrapObject "\\pmod{" "}
  2310. "]} then {
  2311.         message "parenthesized mod set"
  2312.     } else {
  2313.         message "enter formula"
  2314. #--------------------------------------------------------------------------
  2315. # Large Ops:
  2316. #--------------------------------------------------------------------------
  2317. proc insertLargeOp {commandName} {
  2318.     checkMathMode "$commandName" 1
  2319.     set currentPos [getPos]
  2320.     insertObject "\\$commandName\_{
  2321.     goto $currentPos
  2322.     nextTabStop
  2323. proc sum {} {insertLargeOp "sum"}
  2324. proc prod {} {insertLargeOp "prod"}
  2325. proc coprod {} {insertLargeOp "coprod"}
  2326. proc int {} {insertLargeOp "int"}
  2327. proc oint {} {insertLargeOp "oint"}
  2328. proc bigcap {} {insertLargeOp "bigcap"}
  2329. proc bigcup {} {insertLargeOp "bigcup"}
  2330. proc bigsqcup {} {insertLargeOp "bigsqcup"}
  2331. proc bigvee {} {insertLargeOp "bigvee"}
  2332. proc bigwedge {} {insertLargeOp "bigwedge"}
  2333. proc bigodot {} {insertLargeOp "bigodot"}
  2334. proc bigotimes {} {insertLargeOp "bigotimes"}
  2335. proc bigoplus {} {insertLargeOp "bigoplus"}
  2336. proc biguplus {} {insertLargeOp "biguplus"}
  2337. #--------------------------------------------------------------------------
  2338. # Delimiters:
  2339. #--------------------------------------------------------------------------
  2340. proc delimitObject {leftDelim rightDelim} {
  2341.     if {[wrapObject $leftDelim $rightDelim]} then {
  2342.         message "formula delimited"
  2343.     } else {
  2344.         message "enter formula"
  2345. proc parentheses {} { checkMathMode "parentheses" 1; delimitObject "(" ")
  2346. proc brackets {} { checkMathMode "brackets" 1; delimitObject "\[" "\]
  2347. proc braces {} { checkMathMode "braces" 1; delimitObject "\\\{" "\\\}
  2348. proc absoluteValue {} { checkMathMode "absoluteValue" 1; delimitObject "|" "|
  2349. proc getDelims {} {
  2350.     catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" \
  2351.                   "brackets" "braces" "angle brackets" "vertical bars" \
  2352.                   "double bars" "ceiling" "floor"} delimType
  2353.     if {$delimType != "cancel"} then {
  2354.         switch $delimType {
  2355.             "parentheses" {
  2356.                 set leftDelim "("
  2357.                 set rightDelim ")"
  2358.             "brackets" {
  2359.                 set leftDelim "\["
  2360.                 set rightDelim "\]"
  2361.             "braces" {
  2362.                 set leftDelim "\\\{"
  2363.                 set rightDelim "\\\}"
  2364.             "vertical bars" {
  2365.                 set leftDelim "|"
  2366.                 set rightDelim "|"
  2367.             "double bars" {
  2368.                 set leftDelim "\\|"
  2369.                 set rightDelim "\\|"
  2370.             "angle brackets" {
  2371.                 set leftDelim "\\langle"
  2372.                 set rightDelim "\\rangle"
  2373.             "ceiling" {
  2374.                 set leftDelim "\\lceil"
  2375.                 set rightDelim "\\rceil"
  2376.             "floor" {
  2377.                 set leftDelim "\\lfloor"
  2378.                 set rightDelim "\\rfloor"
  2379.             default {
  2380.                 alertnote "\"$delimType\" not recognized"
  2381.                 return ""
  2382.         return [list $leftDelim $rightDelim]
  2383.     } else {return ""}
  2384. proc otherDelims {} {
  2385.     checkMathMode "otherDelims" 1
  2386.     set delims [getDelims]
  2387.     if {$delims != ""} then {
  2388.         set leftDelim [lindex $delims 0]
  2389.         set rightDelim [lindex $delims 1]
  2390.         delimitObject "$leftDelim" "$rightDelim
  2391. proc {half-openInterval} {} {
  2392.     checkMathMode "half-openInterval" 1; delimitObject "(" "\]
  2393. proc {half-closedInterval} {} {
  2394.     checkMathMode "half-closedInterval" 1; delimitObject "\[" ")
  2395. proc insertBigDelims {leftDelim rightDelim isMultiline} {
  2396.     checkMathMode "insertBigDelims" 1
  2397.     if {$isMultiline} then {
  2398.         doWrapStructure $leftDelim "" $rightDelim
  2399.     } else {
  2400.         if { [wrapObject $leftDelim $rightDelim] } then {
  2401.             message "formula delimited"
  2402.         } else {
  2403.             message "enter formula"
  2404. proc bigParens {} {
  2405.     checkMathMode "bigParens" 1; insertBigDelims "\\left(" "\\right)
  2406. proc multiBigParens {} {
  2407.     checkMathMode "multiBigParens" 1; insertBigDelims "\\left(" "\\right)
  2408. proc bigBrackets {} {
  2409.     checkMathMode "bigBrackets" 1; insertBigDelims "\\left\[" "\\right\]
  2410. proc multiBigBrackets {} {
  2411.     checkMathMode "multiBigBrackets" 1; insertBigDelims "\\left\[" "\\right\]
  2412. proc bigBraces {} {
  2413.     checkMathMode "bigBraces" 1; insertBigDelims "\\left\\\{" "\\right\\\}
  2414. proc multiBigBraces {} {
  2415.     checkMathMode "multiBigBraces" 1; insertBigDelims "\\left\\\{" "\\right\\\}
  2416. proc bigAbsValue {} {
  2417.     checkMathMode "bigAbsValue" 1; insertBigDelims "\\left|" "\\right|
  2418. proc multiBigAbsValue {} {
  2419.     checkMathMode "multiBigAbsValue" 1; insertBigDelims "\\left|" "\\right|
  2420. proc doOtherBigDelims {name isMultiline} {
  2421.     checkMathMode $name 1
  2422.     set delims [getDelims]
  2423.     if {$delims != ""} then {
  2424.         append leftDelim "\\left" [lindex $delims 0]
  2425.         append rightDelim "\\right" [lindex $delims 1]
  2426.         insertBigDelims "$leftDelim" "$rightDelim
  2427. " $isMultiline
  2428. proc otherBigDelims {} {
  2429.     doOtherBigDelims "otherBigDelims" 0
  2430. proc otherMultiBigDelims {} {
  2431.     doOtherBigDelims "otherMultiBigDelims" 1
  2432. proc bigLeftBrace {} {
  2433.     checkMathMode "bigLeftBrace" 1
  2434.     insertBigDelims "\\left\\\{" "\\right.
  2435. proc multiBigLeftBrace {} {
  2436.     checkMathMode "multiBigLeftBrace" 1
  2437.     insertBigDelims "\\left\\\{" "\\right.
  2438. proc doOtherMixedBigDelims {name isMultiline} {
  2439.     checkMathMode $name 1
  2440.     catch {prompt "Choose LEFT delimiter:" "parenthesis" "" "parenthesis" \
  2441.                   "bracket" "brace" "vertical bar" "double bar" \
  2442.                   "angle bracket" "ceiling" "floor" "slash" "backslash" \
  2443.                   "none"} delimType
  2444.     if {$delimType != "cancel"} then {
  2445.         switch $delimType {
  2446.             "parenthesis" {set leftDelim "("}
  2447.             "bracket" {set leftDelim "\["}
  2448.             "brace" {set leftDelim "\\\{"}
  2449.             "vertical bar" {set leftDelim "|"}
  2450.             "double bar" {set leftDelim "\\|"}
  2451.             "angle bracket" {set leftDelim "\\langle"}
  2452.             "ceiling" {set leftDelim "\\lceil"}
  2453.             "floor" {set leftDelim "\\lfloor"}
  2454.             "slash" {set leftDelim "/"}
  2455.             "backslash" {set leftDelim "\\backslash"}
  2456.             "none" {set leftDelim "."}
  2457.             default {
  2458.                 alertnote "\"$delimType\" not recognized"
  2459.                 return
  2460.         catch {prompt "Choose RIGHT delimiter:" "parenthesis" "" "parenthesis" \
  2461.                       "bracket" "brace" "vertical bar" "double bar" \
  2462.                       "angle bracket" "ceiling" "floor" "slash" "backslash" \
  2463.                       "none"} delimType
  2464.         if {$delimType != "cancel"} then {
  2465.             switch $delimType {
  2466.                 "parenthesis" {set rightDelim ")"}
  2467.                 "bracket" {set rightDelim "\]"}
  2468.                 "brace" {set rightDelim "\\\}"}
  2469.                 "vertical bar" {set rightDelim "|"}
  2470.                 "double bar" {set rightDelim "\\|"}
  2471.                 "angle bracket" {set rightDelim "\\rangle"}
  2472.                 "ceiling" {set rightDelim "\\rceil"}
  2473.                 "floor" {set rightDelim "\\rfloor"}
  2474.                 "slash" {set rightDelim "/"}
  2475.                 "backslash" {set rightDelim "\\backslash"}
  2476.                 "none" {set rightDelim "."}
  2477.                 default {
  2478.                     alertnote "\"$delimType\" not recognized"
  2479.                     return
  2480.                 }
  2481.             insertBigDelims "\\left$leftDelim" "\\right$rightDelim
  2482. " $isMultiline
  2483. proc otherMixedBigDelims {} {
  2484.     doOtherMixedBigDelims "otherMixedBigDelims" 0
  2485. proc otherMultiMixedBigDelims {} {
  2486.     doOtherMixedBigDelims "otherMultiMixedBigDelims" 1
  2487. #--------------------------------------------------------------------------
  2488. # Accents:
  2489. #--------------------------------------------------------------------------
  2490. proc acute {} {
  2491.     checkMathMode "acute" 1
  2492.     if {[isSelection] > 1} then {
  2493.         alertnote "Warning: only a single character may be accented!"
  2494.     if {[wrapObject "\\acute{" "}
  2495. "]} then {
  2496.         message "accent set"
  2497.     } else {
  2498.         message "enter one character"
  2499. proc bar {} {
  2500.     checkMathMode "bar" 1
  2501.     if {[isSelection] > 1} then {
  2502.         alertnote "Warning: only a single character may be accented!"
  2503.     if {[wrapObject "\\bar{" "}
  2504. "]} then {
  2505.         message "accent set"
  2506.     } else {
  2507.         message "enter one character"
  2508. proc breve {} {
  2509.     checkMathMode "breve" 1
  2510.     if {[isSelection] > 1} then {
  2511.         alertnote "Warning: only a single character may be accented!"
  2512.     if {[wrapObject "\\breve{" "}
  2513. "]} then {
  2514.         message "accent set"
  2515.     } else {
  2516.         message "enter one character"
  2517. proc check {} {
  2518.     checkMathMode "check" 1
  2519.     if {[isSelection] > 1} then {
  2520.         alertnote "Warning: only a single character may be accented!"
  2521.     if {[wrapObject "\\check{" "}
  2522. "]} then {
  2523.         message "accent set"
  2524.     } else {
  2525.         message "enter one character"
  2526. proc dot {} {
  2527.     checkMathMode "dot" 1
  2528.     if {[isSelection] > 1} then {
  2529.         alertnote "Warning: only a single character may be accented!"
  2530.     if {[wrapObject "\\dot{" "}
  2531. "]} then {
  2532.         message "accent set"
  2533.     } else {
  2534.         message "enter one character"
  2535. proc ddot {} {
  2536.     checkMathMode "ddot" 1
  2537.     if {[isSelection] > 1} then {
  2538.         alertnote "Warning: only a single character may be accented!"
  2539.     if {[wrapObject "\\ddot{" "}
  2540. "]} then {
  2541.         message "accent set"
  2542.     } else {
  2543.         message "enter one character"
  2544. proc grave {} {
  2545.     checkMathMode "grave" 1
  2546.     if {[isSelection] > 1} then {
  2547.         alertnote "Warning: only a single character may be accented!"
  2548.     if {[wrapObject "\\grave{" "}
  2549. "]} then {
  2550.         message "accent set"
  2551.     } else {
  2552.         message "enter one character"
  2553. proc hat {} {
  2554.     checkMathMode "hat" 1
  2555.     if {[isSelection] > 1} then {
  2556.         alertnote "Warning: only a single character may be accented!"
  2557.     if {[wrapObject "\\hat{" "}
  2558. "]} then {
  2559.         message "accent set"
  2560.     } else {
  2561.         message "enter one character"
  2562. proc tilde {} {
  2563.     checkMathMode "tilde" 1
  2564.     if {[isSelection] > 1} then {
  2565.         alertnote "Warning: only a single character may be accented!"
  2566.     if {[wrapObject "\\tilde{" "}
  2567. "]} then {
  2568.         message "accent set"
  2569.     } else {
  2570.         message "enter one character"
  2571. proc vec {} {
  2572.     checkMathMode "vec" 1
  2573.     if {[isSelection] > 1} then {
  2574.         alertnote "Warning: only a single character may be accented!"
  2575.     if {[wrapObject "\\vec{" "}
  2576. "]} then {
  2577.         message "accent set"
  2578.     } else {
  2579.         message "enter one character"
  2580. proc widehat {} {
  2581.     checkMathMode "widehat" 1
  2582.     if {[isSelection] > 3} then {
  2583.         alertnote "Warning: only a few characters may be accented!"
  2584.     if {[wrapObject "\\widehat{" "}
  2585. "]} then {
  2586.         message "accent set"
  2587.     } else {
  2588.         message "enter a few characters"
  2589. proc widetilde {} {
  2590.     checkMathMode "widetilde" 1
  2591.     if {[isSelection] > 3} then {
  2592.         alertnote "Warning: only a few characters may be accented!"
  2593.     if {[wrapObject "\\widetilde{" "}
  2594. "]} then {
  2595.         message "accent set"
  2596.     } else {
  2597.         message "enter a few characters"
  2598. proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
  2599. proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
  2600. #--------------------------------------------------------------------------
  2601. # Grouping:
  2602. #--------------------------------------------------------------------------
  2603. proc underline {} {
  2604.     checkMathMode "underline" 1
  2605.     if {[wrapObject "\\underline{" "}
  2606. "]} then {
  2607.         message "selection underlined"
  2608.     } else {
  2609.         message "enter text"
  2610. proc overline {} {
  2611.     checkMathMode "overline" 1
  2612.     if {[wrapObject "\\overline{" "}
  2613. "]} then {
  2614.         message "selection overlined"
  2615.     } else {
  2616.         message "enter text"
  2617. proc underbrace {} {
  2618.     checkMathMode "underbrace" 1
  2619.     if {[wrapObject "\\underbrace{" "}
  2620. "]} then {
  2621.         message "selection underbraced"
  2622.     } else {
  2623.         message "enter text"
  2624. proc overbrace {} {
  2625.     checkMathMode "overbrace" 1
  2626.     if {[wrapObject "\\overbrace{" "}
  2627. "]} then {
  2628.         message "selection overbraced"
  2629.     } else {
  2630.         message "enter text"
  2631. proc overrightarrow {} {
  2632.     checkMathMode "overrightarrow" 1
  2633.     if {[wrapObject "\\overrightarrow{" "}
  2634. "]} then {
  2635.         message "selection overrightarrowed"
  2636.     } else {
  2637.         message "enter text"
  2638. proc overleftarrow {} {
  2639.     checkMathMode "overleftarrow" 1
  2640.     if {[wrapObject "\\overleftarrow{" "}
  2641. "]} then {
  2642.         message "selection overleftarrowed"
  2643.     } else {
  2644.         message "enter text"
  2645. proc stackrel {} {
  2646.     checkMathMode "stackrel" 1
  2647.     set currentPos [getPos]
  2648.     if {[insertObject "\\stackrel{
  2649. "]} then {
  2650.         goto $currentPos
  2651.         nextTabStop
  2652.         message "1st arg scriptstyle"
  2653. #--------------------------------------------------------------------------
  2654. # Spacing:
  2655. #--------------------------------------------------------------------------
  2656. proc negThin {} {checkMathMode "negThin" 1; insertObject "\\!"}
  2657. proc thin {} {checkMathMode "thin" 1; insertObject "\\,"}
  2658. proc medium {} {checkMathMode "medium" 1; insertObject "\\:"}
  2659. proc thick {} {checkMathMode "thick" 1; insertObject "\\;"}
  2660. proc quad {} {checkMathMode "quad" 1; insertObject "\\quad"}
  2661. proc qquad {} {checkMathMode "qquad" 1; insertObject "\\qquad"}
  2662. proc hspace {} {
  2663.     checkMathMode "hspace" 1
  2664.     if {[wrapObject "\\hspace{" "}
  2665. "]} then {
  2666.         message "spacing set"
  2667.     } else {
  2668.         message "enter the desired horizontal spacing"
  2669. proc vspace {} {
  2670.     checkMathMode "vspace" 1
  2671.     if {[wrapObject "\\vspace{" "}
  2672. "]} then {
  2673.         message "spacing set"
  2674.     } else {
  2675.         message "enter the desired horizontal spacing"
  2676. proc hfill {} {checkMathMode "hfill" 1; insertObject "\\hfill"}
  2677. proc vfill {} {checkMathMode "vfill" 1; insertObject "\\vfill"}
  2678. proc smallskip {} {checkMathMode "smallskip" 1; insertObject "\\smallskip"}
  2679. proc medskip {} {checkMathMode "medskip" 1; insertObject "\\medskip"}
  2680. proc bigskip {} {checkMathMode "bigskip" 1; insertObject "\\bigskip"}
  2681.